XPath - Some Important Abbreviations

admin's picture

The most important abbreviation is thatchild::can be omitted from a location step. In effect,child is the default axis.
For example, a location path
Data/username is short for
There is also an abbreviation for attributes: attribute::can be abbreviated to @.
For example, a location path
/*/*/*/*/*/*/*/perm[@type="admin"]is short for
... and so selects
permchildren with a type attribute with value equal to admin.
//is short for /descendant-or-self::node()/.
For example,
//perm is short for
... and so will select anyperm element in the document (even a perm element that is a document element will be selected by //perm since the document element node is a child of the root node);
Data//perm is short for
... and so will select all perm descendants of Data children.
  • A location step of .. is short for parent::node().
For example,
../title is short for
... and so will select the title children of the parent of the context node
  • Example that can be tested on example XML_example.xml:
//getUserToken/usertoken/permissions/../usernameis short for