In XPath, there are seven kinds of nodes: element, attribute, text, namespace, processing-instruction, comment, and document (root) nodes.
在XPath中有七種nodes(節(jié)):元素,屬性,文字,命名空間,處理說(shuō)明,注釋,和文檔(根)節(jié)。
XPath Terminology
XPath術(shù)語(yǔ)
Nodes/節(jié)
In XPath, 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).
XML文檔被視為數(shù)狀的節(jié)。樹(shù)的根部被稱為文檔的節(jié)(或根節(jié))。
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文檔的節(jié)有:
<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.
原子值是那些沒(méi)有子或父的節(jié)(無(wú)上下關(guān)系)。
Example of atomic values:
舉例中的原子值:
J K. Rowling
"en"
Items
項(xiàng)目
Items are atomic values or nodes.
項(xiàng)目是原子值或節(jié)。
Relationship of Nodes
節(jié)之間的關(guān)系
Parent/父
Each element and attribute has one parent.
每個(gè)元素和屬性有一父親。
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.
元素節(jié)可能有0個(gè)或多個(gè)子
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.
節(jié)的父,父的父....都為祖
In the following example; the ancestors of the title element are the book element and the bookstore element:
下面的舉例中:book元素和bookstore元素都為title元素的祖元素
<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.
節(jié)的子,子的子...都為孫
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>