XLink and XPointerSyntax
XLink Syntax
In HTML, we know that the <a> element can define hyperlinks. However, XML does not work this way. In an XML document, you can use any name you need - therefore, it is impossible for browsers to predict which hyperlink elements may be invoked in an XML document.
The way to define hyperlinks in an XML document is to place markup on elements that can be used as hyperlinks.
Below is a simple example of using XLink in an XML document to create a link:
<homepages xmlns:xlink="http://www.w3.org/1999/xlink">
<homepage xlink:type="simple"
xlink:href="../index.html">Visit Example</homepage>
<homepage xlink:type="simple"
xlink:href="http://www.w3.org">Visit W3C</homepage>
</homepages>
In order to access the attributes and features of XLink, we must declare the XLink namespace at the top of the document.
The XLink namespace is: "http://www.w3.org/1999/xlink".
The xlink:type and xlink:href attributes in the <homepage> element define the type and href attributes from the XLink namespace.
xlink:type="simple" creates a simple two-ended link (meaning "from here to there"). Later we will examine multi-ended links (multi-directional).
XPointer Syntax
In HTML, we can create a hyperlink that points both to an HTML page and to a bookmark within that HTML page (using #).
Sometimes, it is more beneficial to be able to point to more specific content. For example, we may need to point to the third item of a particular list, or to the second line of the fifth paragraph. This is very easy to accomplish with XPointer.
If the hyperlink points to an XML document, we can append the XPointer part to the URL in the xlink:href attribute, thereby navigating (via XPath expressions) to a specific location in the document.
For example, in the following example, we use XPointer to point to the fifth item in a list through the unique id "rock".