ÍøÂçѧԺ w3popÉçÇø ÍøÂç×ÊÔ´ ITÐÂÎÅ

w3pop.com :: ÍøÂçѧԺ :: Xquery :: XQuery Óï·¨

»áÔ±µÇ½

ÕʺÅ

ÃÜÂë

»Ø´ð

¼ÇסÃÜÂë

Íü¼ÇÃÜÂë? ×¢²á

Xquery
XQuery ½éÉÜ
XQuery ʵÀý
XQuery FLWOR ±í´..
XQuery FLWOR + H..
XQuery ÊõÓï
XQuery Óï·¨
XQuery Ìí¼ÓÔªËØº..
XQuery Ñ¡ÔñºÍ¹ýÂ..
XQuery º¯Êý
XQuery ÕªÒª
XQuery ²Î¿¼

XQuery Óï·¨


×÷Õß:w3pop.com ·­Òë/ÕûÀí:w3pop.com ·¢²¼:2007-04-29 ÐÞ¸Ä:2007-08-22 ä¯ÀÀ:2894 :: ::

XQuery is case-sensitive and XQuery elements, attributes, and variables must be valid XML names.
Xquery Çø·Ö×Öĸ´óСд£¬ËüµÄÔªËØ¡¢ÊôÐÔ¡¢±äÁ¿±ØÐëÊÇÓÐЧµÄXMLÃû³Æ¡£


XQuery Basic Syntax Rules
XQuery µÄ»ù±¾Óï·¨¹æÔò

Some basic syntax rules:
һЩ»ù±¾Óï·¨¹æÔò£º

  • XQuery is case-sensitive
    XQuery Çø·Ö×Öĸ´óСд
  • XQuery elements, attributes, and variables must be valid XML names
    ËüµÄÔªËØ¡¢ÊôÐÔ¡¢±äÁ¿±ØÐëÊÇÓÐЧµÄXMLÃû³Æ
  • An XQuery string value can be in single or double quotes
    Ò»¸ö XQuery ×Ö·û´®Öµ¿ÉÒÔдÔÚµ¥ÒýºÅÀï»òË«ÒýºÅÀï
  • An XQuery variable is defined with a $ followed by a name, e.g. $bookstore
    Ò»¸ö XQuery ±äÁ¿¶¨ÒåÊÇÔÚ“$”µÄ·ûºÅºóÃæ¸úÉÏÃû³ÆµÈ£¬ÀýÈ磺$bookstore
  • XQuery comments are delimited by (: and :), e.g. (: XQuery Comment :)
    XQuery ×¢ÊÍʹÓà “(: ”ºÍ“ :)” ½øÐзֽ磬ÀýÈç (: XQuery Comment :)

XQuery Conditional Expressions
XQuery µÄÌõ¼þ±í´ïʽ

"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
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 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>
<child>Harry Potter</child>
<adult>Learning XML</adult>
<adult>XQuery Kick Start</adult>

 


XQuery Comparisons
XQuery ±È½Ï

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
have values greater than 10.
Èç¹ûËùÓÐÉÏÊöqµÄÊôÐÔÖµ´óÓÚ10£¬ÄÇô£¬±í´ïʽ½«·µ»Ø“true”£¨Õ棩
$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.
Èç¹û±í´ïʽ·µ»ØµÄqÊôÐÔÖУ¬Ö»ÓÐÒ»¸öqÖµ´óÓÚ10£¬ÄÇô£¬ÉÏÊö±í´ïʽ²Å·µ»Ø“true”£¨Õ棩£»·ñÔò£¬½«²úÉú´íÎó¡£

ÆÀÂÛ (0) All