XQuery is case-sensitive and XQuery elements, attributes, and variables must have valid XML names.
A D V E R T I S E M E N T
XQuery Basic Syntax Rules
Some basic syntax rules:
XQuery is case-sensitive one
XQuery elements, attributes, and variables must have valid
XML names
An XQuery string value can be in the single or double quotes
An XQuery variable is defined with a $ sign followed by a
name, e.g. $bookstore
XQuery comments are always delimited by (: and :), e.g. (:
XQuery Comment :)
XQuery Conditional Expressions
"If-Then-Else" expression are allowed in XQuery.
Look at the example which is given below:
for $x in doc("books.xml")/bookstore/book
return if ($x/@category="CHILDREN")
then <child>{data($x/title)}</child>
else <adult>{data($x/title)}</adult>
Notes on the "if-then-else" syntax: parentheses
around the if expression are always required. else is required, but it
can be just else ().
There are two ways of comparing values are available in XQuery.
1. General comparisons: =, !=, >, >=, <, <=
2. Value comparisons: eq, ne, gt, ge,lt,le,
The difference between the two comparison methods are given below.
Look at the XQuery expressions which is given below:
$bookstore//book/@q > 10
The expression above returns true if any q attributes
have values greater than 10.
$bookstore//book/@q gt 10
The expression above returns true if there is only one
q attribute returned by the expression, and its value
is greater than 10. If more than one q is returned,
an error occurs.