You already know how to link XML documents together with XLink, and isolate specific nodes or node collections with XPath. Now uncover the third and final piece of the XML linking jigsaw - XPointer, an experimental technology from the W3C, which allows you to create XML links to specific points or ranges within an XML document.
To the various node types defined in the XPath specification, XPointer adds two more: points and ranges.
A point is defined as the address of a specific location within an XML document. It is identified by two characteristics: a container node and an index number. The container node is the node which encloses the point, while the index number is an integer which indicates the relative position of the point among the children of the container node.
There are two types of points: node-points, which refer to XML elements, and character-points, which refer to the text contained within XML elements.
The index number within a point definition differs in meaning depending on whether the point is a node-point or a character-point. In the case of a node-point, the index number references a specific child node or nested XML element; in the case of a character-point, it references a particular character of the text string.
Points are defined with XPointer's start-point() and end-point() functions, both of which accept a location path (or collection of location paths) as argument.
A range, defined as the area between two points, is created with the range() function, which returns a collection containing all the elements within the specified range.
An example might help to make this clearer. Consider the following XML document:
<movie id="67" genre="sci-fi">
Jackman, Patrick Stewart and Ian McKellen</cast>
Now, the XPointer
would return a range covering the / element (the document element) and all those
within it - in other words, a range covering the entire document.
The start and end points of this range would be accessible via the XPointers
and would point to the beginning and end of the document respectively.
In a similar manner, the XPointer
would identify the range
while the XPointer
would point to the location immediately preceding the "director" element.