【Introduction to XPath】

XPath stands for XML Path Language, which is a language used to locate parts of an XML (a subset of the standard Universal Markup Language) document. XPath is based on the tree structure of XML, which provides the ability to find nodes in the data structure tree. The original intention of XPath was to use it as a general syntax model between XPointer and XSLT. But XPath was quickly adopted by developers as a small query language.

 

 

expression

XPath uses path expressions to select nodes or sets of nodes in an XML document. These path expressions are very similar to the expressions we see in regular computer file systems. A path expression is a written sequence of steps from one XML node (the current context node) to another node, or set of nodes. These steps are separated by a "/" character, and each step has three components:

Axis description (approach the target node in the most direct way)

Node test (to filter node locations and names)

Node description (used to filter node attributes and child node characteristics)

In general, we use the shorthand syntax. Although the complete axis description is a description that is closer to human language and uses the words and grammar of natural language to write, it is also more verbose by comparison.

 

In XPath, there are seven types of nodes: elements, attributes, text, namespaces, processing instructions, comments, and document nodes (or root nodes).

 

XPath terminology

 

Node

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

 

Basic value (or atomic value, Atomic value)

The base value is a node with no parent or no children.

 

Item

Items are primitive values ​​or nodes.

Node relationship

 

Parent

Every element and attribute has a parent.

 

子(Children)

An element node can have zero, one, or more children.

 

Sibling

Nodes with the same parent

 

Ancestor

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

 

Descendant

A child of a node, a child of a child, etc.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326848529&siteId=291194637