XPath Axes)

Source: Internet
Author: User

XML instance document

We will use this XML document in the following example:

<?xml version="1.0" encoding="ISO-8859-1"?><bookstore><book>  <title lang="eng">Harry Potter</title>  <price>29.99</price></book><book>  <title lang="eng">Learning XML</title>  <price>39.95</price></book></bookstore>
XPath axis

The axis defines a node set relative to the current node.

Axis name Result
Ancestor Select all the ancestors of the current node (parent, grandfather, etc)
Ancestor-or-self Select all the founders of the current node (parent, grandfather, etc.) and the current node itself
Attribute Select all attributes of the current node
Child Select all child elements of the current node.
Descendant Select all descendant elements (child, sun, etc.) of the current node ).
Descendant-or-self Select all descendant elements (child, sun, etc.) of the current node and the current node itself.
Following Select all nodes after the end label of the current node in the document.
Namespace Select All namespace nodes of the current node
Parent Select the parent node of the current node.
Preceding Select all nodes before the start label of the current node in the document.
Preceding-sibling Select all peer nodes before the current node.
Self Select the current node.
Location Path expression

The location path can be absolute or relative.

The absolute path starts with a forward slash (/), but the relative path does not. In either case, the path contains one or more steps, and each step is separated by a slash:

Absolute path:
/step/step/...
Relative Path:
step/step/...

Each step is calculated based on the nodes in the current node set.

Steps include:
Axis)
Define the tree relationship between the selected node and the current node
Node-test)
Recognizes nodes inside a certain axis
Zero or more predicates (predicate)
Further refine the selected node set
Step Syntax:
Axis name: node test [predicates]
Instance
Example Result
Child: Book Select the book nodes of all the child elements of the current node
Attribute: Lang Select the lang attribute of the current node
Child ::* Select all child elements of the current node
Attribute ::* Select all attributes of the current node
Child: Text () Select all text subnodes of the current node
Child: node () Select All subnodes of the current node
Descendant: Book Select All book descendants of the current node
Ancestor: Book Select All book predecessors of the current node
Ancestor-or-self: Book Select all the book predecessors of the current node and the current node (if this node is a book node)
Child: */child: Price Select all price grandchildren of the current node.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.