YouTip LogoYouTip

Xpointer Example

* * * Let’s learn some basic XPointer syntax by studying an example. * * * ## XPointer Example In this example, we’ll show you how to use XPointer in combination with XLink to point to a specific part of another document. We’ll start by examining the target XML document (i.e., the document we want to link to). * * * ## Target XML Document The target XML document is named "dogbreeds.xml" and lists several different dog breeds: The Rottweiler's ancestors were probably Roman drover dogs..... Confident, bold, alert and imposing, the Rottweiler is a popular choice for its ability to protect.... One of the earliest uses of retrieving dogs was to help fishermen retrieve fish from the water.... The flat-coated retriever is a sweet, exuberant, lively dog that loves to play and retrieve.... View the ["dogbreeds.xml" file](#) in your browser. **Note that the XML document above uses the `id` attribute on each element we need to link to!** * * * ## XML Linking Document XPointer allows you not only to link to entire documents (as with XLink), but also to specific parts of a document. To link to a specific part of a page, append a hash symbol (#) followed by an XPointer expression to the URL in the `xlink:href` attribute. The expression `_#xpointer(id("Rottweiler"))_` references the element in the target document whose `id` value is `"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 via its `id`, XPointer supports a shorthand form. You can simply use the `id` value directly, like this: `_xlink:href="http://dog.com/dogbreeds.xml#Rottweiler"_`. The following XML document references information about each dog breed using XLink and XPointer: Anton is my favorite dog. He has won a lot of..... Pluto is the sweetest dog on earth......
← Xlink SummaryXlink Example β†’