In XPath, there are seven kinds of nodes: element, attribute, text, namespace, processing-instruction, comment, and document (root) nodes.
在XPath中有七種nodes(節):元素,屬性,文字,命名空間,處理說明,注釋,和文檔(根)節。
XPath Terminology
XPath術語
Nodes/節
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文檔被視為數狀的節。樹的根部被稱為文檔的節(或根節)。
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.
元素節可能有0個或多個子
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:
下面的舉例中: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.
節的子,子的子...都為孫
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>