XQuery Syntax

XQuery ມີຄວາມກະຈັງຕໍ່ຄວາມນ້ອຍ-ໃຫຍ່, ປະກອບ XQuery, ປະສົມປະສານ ແລະ ສະປະກອບ ຕ້ອງເປັນຊື່ຂອງ XML ທີ່ມີຄວາມການປົກກະຕິ.

ກົດລະບຽບພື້ນຖານ XQuery:

ກົດລະບຽບຂໍ້ມູນພື້ນຖານ:

  • XQuery ມີຄວາມກະຈັງຕໍ່ຄວາມນ້ອຍ-ໃຫຍ່.
  • ປະກອບ XQuery, ປະສົມປະສານ ແລະ ສະປະກອບ ຕ້ອງເປັນຊື່ຂອງ XML ທີ່ມີຄວາມການປົກກະຕິ.
  • ຄວາມຂອງ XQuery ສາມາດນຳໃຊ້ຄວາມສະແດງກັບເງິນນິວານຍາກລາຍການຫຼັງຄື ສະແດງກັບການໃຊ້ການສະແດງຂອງການບັນທຶກ
  • ສະປະກອບ XQuery ຖືກອອກອາກາດດ້ວຍ "$" ແລະ ຕ້ອງມີຊື່ຫຼັກການປະກອບ ວ່າ $bookstore
  • ການຈັດອອກບັນທຶກ XQuery ຖືກແຕ່ງຕັ້ງໂດຍ (: ແລະ :) ວ່າ (: XQuery ບັນທຶກ :)

ກົດລະບຽບຂໍ້ມູນ XQuery

"If-Then-Else" ສາມາດນຳໃຊ້ໃນ XQuery.

ບັນດາຄວາມທີ່ຕ້ອງເບິ່ງຢູ່ລັງຈາກນີ້:

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 example:

<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.