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

XPath Axis (Axes)


May 28, 2021 XPath


Table of contents


XPath axis (Axes).

This section introduces you to the axis of XPath, which allows you to define a set of nodes relative to the current node.

XML instance documentation

We'll 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 (Axes)

The axis defines the set of nodes relative to the current node.

The name of the axis Results
ancestor Select all ancestors (parent, grandfather, etc.) of the current node.
ancestor-or-self Select all ancestors of the current node (parent, grandfather, etc.) and the current node itself.
attribute Select all the properties of the current node.
child Select all child elements of the current node.
descendant Select all descendant elements (children, grandchildren, etc.) of the current node.
descendant-or-self Select all descendant elements (children, grandchildren, etc.) of the current node, as well as the current node itself.
following Select all nodes after the end label of the current node in the document.
namespace Select all namespace nodes for the current node.
parent Select the parent 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.

In the next section, we'll cover the XPath operator.