The best way to explain XQuery is this: XQuery is to XML what SQL is to database tables.
XQuery is designed to query XML data - not just XML files, but any data that can be represented in XML form, including databases.
XQuery syntax syntax
XQuery is case-sensitive, and XQuery elements, attributes, and variables must be legal XML names.
XQuery syntax example
for $x in doc("books.xml")/bookstore/book returnif ($x/@category="CHILDREN") then <child>{data($x/title)}</child> else <adult>{data($x/title)}</adult>
Please note the syntax of "If-Then-Else": the parentheses after the if expression are required. else is also required, but just "else ()" will work.
The result of the above example:
<adult>Everyday Italian</adult> <child>Harry Potter</child> <adult>Learning XML</adult> <adult>XQuery Kick Start</adult>