XPath 術(shù)語
節(jié)點(Node)
在XPath中,有七種類型的節(jié)點:元素、屬性、文本、命名空間、處理指令、注釋以及文檔(根)節(jié)點。XML文檔是被作為節(jié)點樹來對待的。樹的根被稱為文檔節(jié)點或者根節(jié)點。
請看下面這個XML文檔:
以下為引用的內(nèi)容:
<?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>
上面的XML文檔中的節(jié)點例子:
以下為引用的內(nèi)容:
<bookstore>(文檔節(jié)點)
<author>J K. Rowling</author>(元素節(jié)點)
lang="en"(屬性節(jié)點)
基本值(或稱原子值,Atomic value)
基本值是無父或無子的節(jié)點。
基本值的例子:
J K. Rowling
"en"
項目(Item)
項目是基本值或者節(jié)點。
節(jié)點關(guān)系
父(Parent)
每個元素以及屬性都有一個父。
在下面的例子中,book元素是title、author、year以及price元素的父:
以下為引用的內(nèi)容:
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
子(Children)
節(jié)點元素可有零個、一個或多個子。
在下面的例子中,title、author、year以及price元素都是book元素的子:
以下為引用的內(nèi)容:
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
同胞(Sibling)
擁有相同的父的節(jié)點
在下面的例子中,title、author、year以及price元素都是同胞:
以下為引用的內(nèi)容:
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
先輩(Ancestor)
某節(jié)點的父、父的父,等等。
在下面的例子中,title元素的先輩是book元素和bookstore元素:
以下為引用的內(nèi)容:
<bookstore>
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
后代(Descendant)
某個節(jié)點的子,子的子,等等。
在下面的例子中,bookstore的后代是book、title、author、year以及price元素:
以下為引用的內(nèi)容:
<bookstore>
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
新聞熱點
疑難解答