Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

XPointer instance


May 28, 2021 XLink


Table of contents


XPointer instance

In this section, you'll learn to use XPointer syntax.

Let's learn some basic XPointer syntax by studying an example.


XPointer instance

In this example, we'll show you how to use XPointer and combine XLink to point to a specific part of another document.

We'll start by studying the target XML document (that is, the document we want to link to).


Target XML documentation

The target XML document, called "dogbreeds.xml", lists a number of different dog species:

<?xml version="1.0" encoding="ISO-8859-1"?>

<dogbreeds>

<dog breed="Rottweiler" id="Rottweiler">
<picture url="http://dog.com/rottweiler.gif" />
<history>The Rottweiler's ancestors were probably Roman
drover dogs.....</history>
<temperament>Confident, bold, alert and imposing, the Rottweiler
is a popular choice for its ability to protect....</temperament>
</dog>

<dog breed="FCRetriever" id="FCRetriever">
<picture url="http://dog.com/fcretriever.gif" />
<history>One of the earliest uses of retrieving dogs was to
help fishermen retrieve fish from the water....</history>
<temperament>The flat-coated retriever is a sweet, exuberant,
lively dog that loves to play and retrieve....</temperament>
</dog>

</dogbreeds>

View the "dogbreeds.xml" file in your browser.

Note that the XML document above uses the id property on each element we need to link to!


XML linked documents

XPointer allows you to link to specific parts of a document, not just to the entire document (when using XLink). To link to a specific part of the page, add a hashtag and an XPointer expression after the URL in the xlink:href property.

Expression: #xpointer (id ("Rottweiler") refers to an element in the target document with an id value of "Rottweiler".

Therefore, the xlink:href property will look something like this: xlink:href"http://dog.com/dogbreeds.xml _blank

However, XPointer allows short form when linking to an element using id. You can use the value of the id directly, as follows: xlink:href"http://dog.com/dogbreeds.xml#Rottweiler" rel=external nofollow"target="_blank" rel="external nofollow target"_blank"

The following XML documentation refers to each dog's breed information, both via XLink and XPointer:

<?xml version="1.0" encoding="ISO-8859-1"?>

<mydogs xmlns:xlink="http://www.w3.org/1999/xlink">

<mydog xlink:type="simple"
xlink:href="http://dog.com/dogbreeds.xml#Rottweiler" rel="external nofollow" target="_blank" rel="external nofollow" target="_blank" >
<description xlink:type="simple"
xlink:href="http://myweb.com/mydogs/anton.gif" rel="external nofollow" target="_blank" >
Anton is my favorite dog. He has won a lot of.....
</description>
</mydog>

<mydog xlink:type="simple"
xlink:href="http://dog.com/dogbreeds.xml#FCRetriever" rel="external nofollow" target="_blank" >
<description xlink:type="simple"
xlink:href="http://myweb.com/mydogs/pluto.gif" rel="external nofollow" target="_blank" >
Pluto is the sweetest dog on earth......
</description>
</mydog>

</mydogs>