Xquery
Xquery
BY
N.RAVIKUMAR
Xquery
XQuery is designed to query XML data - not just XML
files, but anything that can appear as XML, including
databases.
Manage
> Query (Insert, Update, Delete).
> Multiple users
> Complex queries
> ACID properties
Xquery Origin
XQuery 1.0 was developed by the XML Query
working group of the W3C.
Element constructors
FLWOR expressions
Path expressions
Path expressions are used to navigate input
documents to select elements and attributes of
interest.
A path expression is made up of one or more
steps that are separated by a slash(/) or double
slashes(//).
e.g
doc(“marks.xml”)/markssummary/@student
(Returns all attributes of element student)
Element Construction
An XQuery expression can construct new
values or structures
Example: Consider the path expressions.
LET $x = expression
Binds $x to the entire list expr
Useful for common sub-expressions and for
aggregations
Cont..
FOR
FOR$x
$xIN
INdocument("bib.xml")/bib/book
document("bib.xml")/bib/book
RETURN
RETURN<result>
<result>$x
$x</result>
</result>
Returns:
<result> <book>...</book></result>
<result> <book>...</book></result>
<result> <book>...</book></result>
...
LET
LET$x
$xIN
INdocument("bib.xml")/bib/book
document("bib.xml")/bib/book
RETURN
RETURN<result>
<result>$x
$x</result>
</result>
Returns:
<result> <book>...</book>
<book>...</book>
<book>...</book>
...
</result>
XQuery Example
Find all book titles published after 1995:
FOR
FOR$x
$xIN
INdocument("bib.xml")/bib/book
document("bib.xml")/bib/book
WHERE
WHERE$x/year
$x/year>>1995
1995
RETURN
RETURN$x/title
$x/title
Result:
<title> abc </title>
<title> def </title>
<title> ghi </title>
XML and Relational
Data
name phone row row row
John 3634
phone phone phone
name name name
Sue 6343
www.w3.org/TR/xquery
http://www.xml.com/pub/a/2002/10/16/xquery.html
www.brics.dk/~amoeller/XML/querying
THANK YOU