XPath tutoriallogin
XPath tutorial
author:php.cn  update time:2022-04-20 14:10:21

XPath Axes



XML Example 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 Axes

Axis defines a set of nodes relative to the current node.

Axis nameResultancestorSelect all ancestors of the current node ( father, grandfather, etc.). ancestor-or-selfSelects all ancestors (parents, grandfathers, etc.) of the current node as well as the current node itself. attributeSelect all attributes of the current node. childSelect all child elements of the current node. descendantSelect all descendant elements (children, grandchildren, etc.) of the current node. descendant-or-selfSelect all descendant elements (children, grandchildren, etc.) of the current node as well as the current node itself. followingSelect all nodes after the closing tag of the current node in the document. namespaceSelect all namespace nodes of the current node. parentSelect the parent node of the current node. precedingSelect all nodes before the start tag of the current node in the document. preceding-siblingSelect all sibling nodes before the current node. selfSelect the current node.