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.
XPointer evolved as part of the work of the W3C's XML Linking Working Group, which is also responsible for XLink. While developing XLink, the Working Group realized the necessity of a language to address specific nodes - elements or character data - or sets of nodes within an XML document.
This wasn't the only requirement, however - the XML Linking Working Group also identified the following requirements of such a language:
1. XPointers should be based on "descriptive links" - links which identify locations by their context.
2. XPointers should be easy to read and understand; they should also be simple to interpret for browsers and Web servers.
3. It should be possible to create an XPointer for any specific point in a document. Similarly, it should also be possible to create an XPointer that identifies a specific range of data within an XML document.
4. XPointers should include the capability to restrict node selections on the basis of user-imposed constraints, in much the same way as XPath uses predicates.
5. Minor changes to an XML document - changes in whitespace, line breaks and formatting - should not "break" an XPointer.
XPath already existed to meet some of these requirements; however, it is primarily intended for use with XSLT rather than XML links, and therefore does not address some of the more specialized items in the list above.{mospagebreak title=First Steps} Let's look at XPath quickly, and then proceed to XPointer proper.
XPath makes it possible to locate a node, or set of nodes, at any level of an XML document tree, using a thingamajig known as a "location path."
A location path may be either an absolute path, which expresses a location with reference to the root node, or a relative path, which expresses a location with reference to the current node (since this location is always in context to something else, it is also referred to as the "context node"). Location paths are made up of a series of "location steps", each identifying one level in the XPath tree and separated from each other by a forward slash (/).
A location step can be further broken down into three components: there's an "axis", which defines the relationship to use when selecting nodes; a "node test", which specifies the types of nodes to select; and optional "predicates" to filter out unwanted nodes from the resulting collection (I'll explain each of these in detail further down so that they become a little less frightening.)