XML XPointer
XML Pointer Language (XPointer)
Section titled “XML Pointer Language (XPointer)”XPointer extends XPath to allow hyperlinks (often defined using XLink) to point to specific fragments or parts within an XML document, not just the entire document.
What is XPointer?
Section titled “What is XPointer?”- XPointer enables addressing specific points, ranges, or elements within an XML resource.
- It leverages XPath expressions for navigation within the target XML document.
- It allows for more granular linking than standard URL fragment identifiers (like
#id). - XPointer is a W3C Recommendation, but its practical adoption has been limited.
XPointer Browser and Tool Support
Section titled “XPointer Browser and Tool Support”Native support for XPointer (and XLink) in major web browsers is virtually non-existent. You cannot rely on standard browsers to resolve XPointer-based links automatically.
However, the concepts and syntax might be encountered in specialized XML processing tools, document management systems, or specific XML standards that require fine-grained internal linking.
XPointer Example with XLink
Section titled “XPointer Example with XLink”Let’s illustrate how XPointer could be used with XLink to create a link targeting a specific part of another XML document.
Target XML Document (dogbreeds.xml):
Note the use of xml:id which is the standard XML attribute for assigning unique IDs.
<?xml version="1.0" encoding="UTF-8"?><dogbreeds xmlns:xml="http://www.w3.org/XML/1998/namespace"> <dog breed="Rottweiler" xml:id="Rottweiler"> <picture url="http://example.com/rottweiler.jpg"/> <history>The Rottweiler's ancestors were probably Roman drover dogs...</history> <temperament>Confident, bold, alert and imposing...</temperament> </dog> <dog breed="FCRetriever" xml:id="FCRetriever"> <picture url="http://example.com/fcretriever.jpg"/> <history>One of the earliest uses of retrieving dogs was to help fishermen...</history> <temperament>The flat-coated retriever is a sweet, exuberant, lively dog...</temperament> </dog></dogbreeds>Source XML Document (mydogs.xml):
This document uses XLink (xlink:href, xlink:type) to link to parts of dogbreeds.xml.
<?xml version="1.0" encoding="UTF-8"?><mydogs xmlns:xlink="http://www.w3.org/1999/xlink"> <mydog> <description>Anton is my favorite dog. He has won many awards...</description> <!-- Link using XPointer full syntax --> <fact xlink:type="simple" xlink:href="dogbreeds.xml#xpointer(id('Rottweiler'))"> Fact about Rottweiler (Full XPointer) </fact> </mydog> <mydog> <description>Pluto is the sweetest dog on earth...</description> <!-- Link using XPointer shorthand for IDs --> <fact xlink:type="simple" xlink:href="dogbreeds.xml#FCRetriever"> Fact about Flat-Coated Retriever (Shorthand) </fact> </mydog></mydogs>Explanation:
- The
xlink:hrefattribute contains the URL of the target document (dogbreeds.xml) followed by a hash (#) and the XPointer expression. xpointer(id('Rottweiler')): This is the full XPointer syntax. It uses an XPath-like functionid()to find the element whosexml:idattribute value is ‘Rottweiler’.#FCRetriever: This is the shorthand XPointer syntax. If the part after the#matches the value of anxml:idattribute in the target document, it directly points to that element.
While powerful in concept, the lack of widespread implementation means XPointer is mainly relevant in specific, closed XML ecosystems or for understanding the history and capabilities of XML technologies.