w3pop.com :: ÍøÂçѧԺ :: Xquery :: XQuery ÊõÓï
In XQuery, there are seven kinds of nodes: element, attribute, text, namespace, processing-instruction, comment, and document (root) nodes.
ÔÚXQueryÖУ¬ÓÐ7Öв»Í¬µÄ½Úµã£ºÔªËØ¡¢ÊôÐÔ¡¢Îı¾¡¢ÃüÃû¿Õ¼ä¡¢´¦ÀíÖ¸Áî¡¢×¢ÊÍ¡¢Îĵµ£¨¸ùĿ¼£©½Úµã¡£
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> </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 are nodes with no children or parent.
“Ô×ÓÖµ”ÊôÐÔֵֻûÓÐ×Ó½ÚµãºÍ¸¸½Úµã¡£
Example of atomic values:
“Ô×ÓÖµ”ÊôÐÔÖµ°¸Àý£º
J K. Rowling "en" |
Items are atomic values or nodes.
“Ïî”ÊÇÖ¸Ô×ÓÖµ»ò½Úµã¡£
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> |
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> |
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> |
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> </bookstore> |
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> </bookstore> |
ÆÀÂÛ (0)
All