在 XQuery 中,有七種節(jié)點(diǎn):元素、屬性、文本、命名空間、處理指令、注釋、以及文檔節(jié)點(diǎn)(或稱為根節(jié)點(diǎn))。
XQuery 術(shù)語
節(jié)點(diǎn)
在 XQuery 中,有七種節(jié)點(diǎn):元素、屬性、文本、命名空間、處理指令、注釋、以及文檔(根)節(jié)點(diǎn)。XML 文檔是被作為節(jié)點(diǎn)樹來對(duì)待的。樹的根被稱為文檔節(jié)點(diǎn)或者根節(jié)點(diǎn)。
請(qǐng)看下面的 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>
<bookstore>
<book>
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
上面的 XML 文檔中的節(jié)點(diǎn)例子:
<bookstore> (文檔節(jié)點(diǎn))
<author>J K. Rowling</author> (元素節(jié)點(diǎn))
lang="en" (屬性節(jié)點(diǎn))
<author>J K. Rowling</author> (元素節(jié)點(diǎn))
lang="en" (屬性節(jié)點(diǎn))
基本值是無父或無子的節(jié)點(diǎn)。
基本值的例子:
J K. Rowling
"en"
"en"
項(xiàng)目
項(xiàng)目是基本值或者節(jié)點(diǎn)。
節(jié)點(diǎn)關(guān)系
父
每個(gè)元素以及屬性都有一個(gè)父。
在下面的例子中,book 元素是 title、author、year 以及 price 元素的父:
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
子(Children)
節(jié)點(diǎn)元素可有零個(gè)、一個(gè)或多個(gè)子。
在下面的例子中,title、author、year 以及 price 元素都是 book 元素的子:
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
同胞(Sibling)
擁有相同的父的節(jié)點(diǎn)。
在下面的例子中,title、author、year 以及 price 元素都是同胞:
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
先輩(Ancestor)
某節(jié)點(diǎn)的父、父的父,等等。
在下面的例子中,title 元素的先輩是 book 元素和 bookstore元素:
<bookstore>
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
后代(Descendant)
某個(gè)節(jié)點(diǎn)的子,子的子,等等。
在下面的例子中,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>
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>