[转载]
原文链接
XPath 术语 (XPath Terminology)
一 节点(Nodes)
In XPath, there are seven kinds of nodes: element, attribute, text, namespace, processing-instruction, comment, and document nodes.
XPath中有7种不同类型的节点:
- element
- attribute
- text
- namespace
- processing-instroduction
- comment
- document nodes
XML documents are treated as trees of nodes. The topmost element of the tree is called the root element.
XML文档被视为节点树。树的最上层元素被称为根节点。
示例:
XML 文档:
<?xml version="1.0" encoding="UTF-8"?>
<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> (root element node)根节点
<author>J K. Rowling</author> (element node)元素节点
lang="en" (attribute node)属性节点
二 原子值(Atomic values)
Atomic values are nodes with no children or parent.
原子值:没有孩子节点或父节点的节点。
示例:
上面XML文档中的原子值为:
J K. Rowling
"en"
三 Items (项目??)
Items are atomic values or nodes.
四 节点之间的关系(Relationship of Nodes)
1 Parent (父节点)
Each element and attribute has one parent.
每个元素或属性都有一个父节点。
示例:
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
The <book> element is the parent of the <title>, <author>, <year>, and <price>.
2 Children (子节点)
Element nodes may have zero, one or more children.
元素节点可能含有0/1/多个孩子节点。
示例:
the title, author, year, and price elements are all children of the book element.
上面XML文档中,<title>,<author>,<year>,<price>全部都是<book>元素的孩子节点。
3 Siblings (兄弟节点)
Nodes that have the same parent.拥有同一父节点的节点,互称为兄弟节点。
示例:
The title, author, year, and price elements are all siblings.
上面XML文档中,<title>,<author>,<year>,<price>互为兄弟节点。
4 Ancestors(祖先)
A node's parent, parent's parent, etc.
一个节点的父节点,父节点的父节点等。
示例:
XML文档
<bookstore>
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
</bookstore>
The ancestors of the title element are the book element and the bookstore element。
节点<title>的祖先有:<book>和<bookstore>。
5 Descendants(后代)
A node's children, children's children, etc.
一个节点的孩子节点,孩子节点的孩子等。
示例:
The descendants of the bookstore element are the book, title, author, year, and price elements.
上述XML文档中,<bookstore>的孩子节点有:<book>,<title>,<author>,<year>,<price>.