XPath Nodes(节)

内容纲要

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>  

发表评论

电子邮件地址不会被公开。 必填项已用*标注