XPointer Example
Let's learn some basic XPointer syntax by studying an example.
XPointer Example
In this example, we will show you how to use XPointer in conjunction with XLink to point to a specific part of another document.
We will start by examining the target XML document (the document we want to link to).
Target XML Document
The target XML document is named "dogbreeds.xml" and it lists various dog breeds:
View the "dogbreeds.xml" file in your browser.
Note that the XML document above uses id attributes on each element we need to link to!
XML Link Document
Not only can you link to the entire document (when using XLink), but XPointer allows you to link to specific parts of the document. To link to a specific part of the page, add a hash (#) followed by an XPointer expression to the URL in the xlink:href attribute.
The expression: #xpointer(id("Rottweiler")) can reference the element in the target document with the id value "Rottweiler".
Thus, the xlink:href attribute would look like this: xlink:href="http://dog.com/dogbreeds.xml#xpointer(id('Rottweiler'))"
However, when linking to an element using its id, XPointer allows for shorthand notation. You can directly use the id value like this: xlink:href="http://dog.com/dogbreeds.xml#Rottweiler".
The following XML document references information about each dog breed, all linked through XLink and XPointer: