Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

XPath node


May 28, 2021 XPath


Table of contents


XPath node

This section gives you an introduction to nodes in XPath, focusing on the relationships between XPath nodes.

XPath term

Node

In XPath, there are seven types of nodes: elements, properties, text, namespaces, processing instructions, comments, and document (root) nodes. X ML documents are treated as node trees. The root of a tree is called a document node or root node.

Take a look at this XML document:

<?xml version="1.0" encoding="ISO-8859-1"?>

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

Examples of nodes in the XML documentation above:

<bookstore> (文档节点)

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

(Attribute node)

Base value (or atomic value, Atomic value)

The base value is a node without a parent or child.

Examples of basic values:

J K. Rowling

"en"

Project

A project is a base value or node.


The node relationship

Parent

Each element and property has a parent.

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

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

Children

Element nodes can have zero, one, or more children.

In the following example, the 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>

Sibling

A node that has the same parent

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

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

Ancestor

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

In the following example, the title element's ancestors were 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>

Descendants

The child of a node, the child of a child, and so on.

In the following example, the bookstore's descendants are the 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>

In the next section, we'll cover the syntax of XPath.