XQuery Syntax

XQuery za a iya da yin kiyasi da har ila 2, element, attribute kuma variable XQuery za a iya da yin sunan XML da ake samarwa.

grammar kwarara XQuery:

koyarwa grammar kwarara:

  • XQuery za a iya da yin kiyasi da har ila 2 kuma kuma za a iya da yin kiyasi da har ila 2.
  • element, attribute kuma variable XQuery za a iya da yin sunan XML da ake samarwa.
  • value string XQuery za a iya amfana ne da tsare ko kuma da kaiwa.
  • variable XQuery za a gina da $ kuma ya tsaya sunan, misali, $bookstore
  • comment XQuery yana biki da kaiwa kuma yana da kaiwa (: XQuery comment :)

expression koyarwa XQuery

"If-Then-Else" za iya a kan XQuery.

ka ikiri baya:

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>

Please note the syntax of "If-Then-Else": the parentheses after the if expression are required. else is also required, but you can also write "else ()".

The result of the above examples:

<adult>Everyday Italian</adult>
<child>Harry Potter</child>
<adult>Learning XML</adult>
<adult>XQuery Kick Start</adult>

XQuery Comparison

In XQuery, there are two methods to compare values.

  1. General comparison: =, !=, <, <=, >, >=
  2. Value comparison: eq, ne, lt, le, gt, ge

The differences between these two comparison methods are as follows:

Please see the following XQuery expression:

$bookstore//book/@q > 10

If the value of the q attribute is greater than 10, the return value of the above expression is true.

$bookstore//book/@q gt 10

If only one q is returned and its value is greater than 10, the expression returns true. If more than one q is returned, an error will occur.