w3pop.com :: ÍøÂçѧԺ :: Xquery :: XQuery Óï·¨
XQuery is case-sensitive and XQuery elements, attributes, and variables must be valid XML names.
Xquery Çø·Ö×Öĸ´óСд£¬ËüµÄÔªËØ¡¢ÊôÐÔ¡¢±äÁ¿±ØÐëÊÇÓÐЧµÄXMLÃû³Æ¡£
Some basic syntax rules:
һЩ»ù±¾Óï·¨¹æÔò£º
"If-Then-Else" expressions are allowed in XQuery.
XQuery ÔÊÐíʹÓà "If-Then-Else" Ìõ¼þ±í´ïʽ¡£
Look at the following example:
ÏÈ¿´¿´ÏÂÃæµÄ°¸Àý£º
for $x in doc("books.xml")/bookstore/book
|
Notes on the "if-then-else" syntax: parentheses around the if expression are required. else is required, but it can be just else ().
ʹÓÓif-then-else"Ìõ¼þÓï¾äʱӦעÒâµÄÓï·¨µã£ºif ±í´ïʽÔÊÐí³öÏÖÔ²À¨ºÅ£»ÁíÍ⣬Èç¹ûʹÓÃÁË“if”£¬¾Í±ØÐëʹÓÓelse”£¬Ò²¿ÉÒÔÊÇelse()¡£
The result of the example above will be:
ÉÏÊö°¸ÀýÊä³öµÄ½á¹ûÈçÏ£º
<adult>Everyday Italian</adult> |
In XQuery there are two ways of comparing values.
XQuery ÓÐÁ½ÖֱȽÏÖµµÄ·½·¨¡£
1. General comparisons: =, !=, <, <=, >, >=
³£¹æ±È½Ï·ûºÅ£º= ¡¢ != ¡¢ < ¡¢ <= ¡¢ > ¡¢ >=
2. Value comparisons: eq, ne, lt, le, gt, ge
ÖµµÄ±È½Ï£ºeq ¡¢ ne ¡¢ lt ¡¢ le ¡¢ gt ¡¢ ge
The difference between the two comparison methods are shown below.
ÏÂÃæÁоÙÁËÁ½ÖֱȽϷ½·¨µÄ²»Í¬Ö®´¦¡£
Look at the following XQuery expressions:
ÏÈ¿´¿´ÏÂÃæµÄXQuery±í´ïʽ£º
$bookstore//book/@q > 10
The expression above returns true if any q attributes $bookstore//book/@q gt 10
The expression above returns true if there is only one |
ÆÀÂÛ (0)
All