Latest web development tutorials

XPath node

XPath term

node

In XPath, there are seven types of nodes: element, attribute, text, namespace, processing instruction, comment, and document (root) nodes. XML document is treated as a node tree. Root of the tree is called the document node or root node.

Look at the following XML document:

<?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>

The above XML document node examples:

<bookstore> (文档节点)

<author>J K. Rowling</author> (元素节点)

lang="en" (属性节点)

The basic value (or atomic values, Atomic value)

The basic value is no father or no child nodes.

Examples of basic values:

J K. Rowling

"en"

Item (Item)

Project is the basic values ​​or nodes.


Node Relationship

Parent (Parent)

Each element and attribute has one parent.

In the following example, book element is the parent title, author, year, and price elements:

<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>

Child (Children)

Element node can have zero, one or more children.

In the following example, title, author, year, and price elements are all children of the book element:

<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>

Compatriots (Sibling)

It has the same parent node

In the following example, title, author, year, and price elements are brothers:

<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>

Ancestor (Ancestor)

The parent of a node, and the parent's parent, and so on.

In the following example, the ancestors of the title element are the book element and the bookstore element:

<bookstore>

<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>

</bookstore>

Offspring (Descendant)

Child of a node, sub-sub, and so on.

In the following example, bookstore offspring is book, title, author, year, and price elements:

<bookstore>

<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>

</bookstore>