XPointers refer to particular parts of or locations in XML documents.
An XPointer is composed of location steps.
The id
absolute location step points to an element with a specified value for an ID
type attribute.
The root
absolute location step points to the root element of an XML document and is generally abbreviated as simply /
.
Location steps can be chained to make more sophisticated compound locators.
Relative location steps select nodes in a document based on their relationship to a context node, generally provided by either an absolute location step or another relative location step.
Each relative location step contains an axis, a node test, and zero or more predicates.
The self
axis points to the context node.
The parent
axis points to the node that contains the context node.
The child
axis points to immediate children of the context node.
The descendant
axis points to all elements contained in the context node.
The descendant-or-self
axis points to all elements contained in the context node as well as the context node itself.
The ancestor
axis points to an element that contains the context node.
The ancestor-or-self
axis points to all elements that contain the context node as well as the context node itself.
The preceding
axis points to any element that comes before the context node.
The following
axis points to any element following the context node.
The preceding-sibling
axis selects from sibling elements that precede the context node.
The following-sibling
axis selects from sibling elements that follow the context node.
The attribute
axis points to an attribute of the context node.
The node test of a relative location step is normally an element name, but may also be the *
wild card to select all elements or one of the keywords comment()
, text()
, processing-instruction()
, or node()
.
The optional predicate of a relative location step is an XPath expression enclosed in square brackets that further narrows down the node set the XPointer refers to.
The string
location term points to a specified block of text in the location source.
The range
axis selects the XML fragment between two XPointers.
A tumbler points to an element by counting children from the root.