ÍøÂçѧԺ 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 ä¯ÀÀ:2012 :: ::

In XQuery, there are seven kinds of nodes: element, attribute, text, namespace, processing-instruction, comment, and document (root) nodes.
ÔÚXQueryÖУ¬ÓÐ7Öв»Í¬µÄ½Úµã£ºÔªËØ¡¢ÊôÐÔ¡¢Îı¾¡¢ÃüÃû¿Õ¼ä¡¢´¦ÀíÖ¸Áî¡¢×¢ÊÍ¡¢Îĵµ£¨¸ùĿ¼£©½Úµã¡£


XQuery ÊõÓï

Nodes
½Úµã

In XQuery, there are seven kinds of nodes: element, attribute, text, namespace, processing-instruction, comment, and document (root) nodes. XML documents are treated as trees of nodes. The root of the tree is called the document node (or root node).
ÔÚXQueryÀÓÐ7Öв»Í¬µÄ½Úµã£ºÔªËØ¡¢ÊôÐÔ¡¢Îı¾¡¢ÃüÃû¿Õ¼ä¡¢´¦ÀíÖ¸Áî¡¢×¢ÊÍ¡¢Îĵµ£¨¸ùĿ¼£©½Úµã£¬XMLÎĵµÊǽڵãÊ÷×´½á¹¹¡£“Ê÷¸ù”³Æ×÷Îĵµ½Úµã£¨»ò¸ù½Úµã£©¡£

Look at the following XML document:
ÏÈ¿´¿´ÏÂÃæÕâ¸öXMLÎĵµ£º

<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book>
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>

<price>29.99</price>
</book>
</bookstore>

Example of nodes in the XML document above:
ÉÏÊöXMLÎĵµÖеĽڵ㰸Àý£º

<bookstore>  (document node)
<author>J K. Rowling</author>  (element node)
lang="en"  (attribute node)

Atomic values
“Ô­×ÓÖµ”ÊôÐÔÖµ

Atomic values are nodes with no children or parent.
“Ô­×ÓÖµ”ÊôÐÔֵֻûÓÐ×Ó½ÚµãºÍ¸¸½Úµã¡£

Example of atomic values:
“Ô­×ÓÖµ”ÊôÐÔÖµ°¸Àý£º

J K. Rowling
"en"

Items
Ïî

Items are atomic values or nodes.
“Ïî”ÊÇÖ¸Ô­×ÓÖµ»ò½Úµã¡£


Relationship of Nodes
½Úµã¼ä¹ØÏµ

Parent
¸¸Àà

Each element and attribute has one parent.
ÿ¸öÔªËØºÍÊôÐÔ¶¼°üº¬Ò»¸ö“¸¸Àà”¡£

In the following example; the book element is the parent of the title, author, year, and price:
ÔÚÏÂÊö°¸ÀýÖУºbookÔªËØÊÇtitle¡¢author¡¢year ºÍ price ÔªËØµÄ¸¸ÀàÔªËØ£º

<book>
<title>Harry Potter</title>

<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>

Children
×ÓÀàÔªËØ

Element nodes may have zero, one or more children.
ÔªËØ½Úµã¿ÉÒÔ°üº¬ÈÎÒâ¸öÊýµÄ×ÓÀàÔªËØ¡£

In the following example; the title, author, year, and price elements are all children of the book element:
ÔÚÏÂÊö°¸ÀýÖУ¬title¡¢author¡¢year ºÍ priceÔªËØ¶¼ÊÇbookÔªËØµÄ×ÓÔªËØ£º

<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>

<price>29.99</price>
</book>

Siblings
ͬÀàÔªËØ

Nodes that have the same parent.
ÓµÓÐÏàͬµÄ¸¸ÀàÔªËØµÄ½Úµã³ÆÎªÍ¬ÀàÔªËØ¡£

In the following example; the title, author, year, and price elements are all siblings:
ÔÚÏÂÊö°¸ÀýÖУ¬title¡¢author¡¢year ºÍ price ÔªËØ¶¼ÊǓͬÀàÔªËØ”£º

<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>

<year>2005</year>
<price>29.99</price>
</book>

Ancestors
׿ÀàÔªËØ

A node's parent, parent's parent, etc.
Ò»¸ö½ÚµãµÄ¸¸ÀàÔªËØ£¬¸¸ÀàÔªËØµÄ¸¸ÀàÔªËØ£¬ÒÔ´ËÀàÍÆ£¬³ÆÎª¸Ã½ÚµãµÄ׿ÀàÔªËØ¡£

In the following example; the ancestors of the title element are the book element and the bookstore element:
ÔÚÏÂÊö°¸ÀýÖУ¬titleÔªËØµÄ “׿ÀàÔªËØ” ÊÇ book ÔªËØºÍ bookstore ÔªËØ¡£

<bookstore>
<book>

<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>

</book>
</bookstore>

Descendants
ËïÀàÔªËØ

A node's children, children's children, etc.
Ò»¸ö½ÚµãµÄ×ÓÀàÔªËØ£¬×ÓÀàÔªËØµÄ×ÓÀàÔªËØ£¬ÒÔ´ËÀàÍÆ£¬³ÆÎªËïÀàÔªËØ¡£

In the following example; descendants of the bookstore element are the book, title, author, year, and price elements:
ÔÚÏÂÊö°¸ÀýÖУ¬bookstore ÔªËØµÄËïÀàÔªËØÊÇbook¡¢title¡¢author¡¢year ºÍ price ÔªËØ£º

<bookstore>
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>

<year>2005</year>
<price>29.99</price>
</book>
</bookstore>

ÆÀÂÛ (0) All