[This article is a reference to www.w3school.com.cn]
XPath is a language used to search for information in XML documents. XPath can be used to traverse elements and attributes in XML documents.
XPath is the main element of W3C XSLT standards, and XQuery and xpointer are also built on XPath expressions.
What is XPath?
- XPath uses path expressions for navigation in XML documents
- XPath contains a standard function library
- XPath is the main element in XSLT.
- XPath is a W3C Standard
XPath path expression
XPath uses path expressions to select nodes or node sets in XML documents. These path expressions are very similar to the expressions we see in conventional computer file systems.
XPath Standard Functions
XPath contains more than 100 built-in functions. These functions are used for string value, numeric value, date and time comparison, node and QNAME processing, sequence processing, logical value, and so on.
XPath terminology
Node)
There are seven types of nodes in XPath: elements, attributes, text, namespaces, processing commands, comments, and document (Root) nodes. XML documents are treated as node trees. The root of a tree is called a document node or a root node.
See 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>
Node example in the XML document above:
<Bookstore> (document node)
<Author> j k. Rowling </author> (element node)
Lang = "en" (attribute node)
Basic value (or atomic value)
The basic value is a node with no parent or child.
Example of the basic value:
J k. Rowling
"EN"
Item)
A project is a basic value or node.
Node relationship
Parent)
Each element and attribute has a parent.
In the preceding example, the book element is the parent of the title, author, year, and price elements.
Child)
Element nodes can have zero, one, or more sub-nodes.
In the above example, the title, author, year, and price elements are all child of the book element.
Sibling)
Nodes with the same parent
In the preceding example, the title, author, year, and price elements are all siblings.
Advanced (ancestor)
The parent and parent of a node.
In the above example, the title element is a book element and a bookstore element.
Descendant (descendant)
The child of a node, the child of the child, and so on.
In the above example, the future generations of bookstore are book, title, author, year, and price.