XLink and XPointer Syntax
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 - thus, for a browser, it is impossible to predict what kind of hyperlink element can be called in an XML document.
The way to define hyperlinks in an XML document is to place tags on elements that can act as hyperlinks.
Here is a simple example of using XLink to create links in an XML document:
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"). We will explore multi-ended links (multi-directional) later.
XPointer Syntax
In HTML, we can create a hyperlink that points to both an HTML page and a bookmark within that page (using #
).
Sometimes, it is more beneficial to point to more specific content. For example, we need to point to the third item in a specific list, or to the second line of the fifth paragraph. This is easily done with XPointer.
If a hyperlink points to an XML document, we can add the XPointer part to the URL in the xlink:href
attribute, allowing us to navigate (using XPath expressions) to a specific location within the document.
For example, in the following example, we use XPointer to point to the fifth item in a list with the unique id "rock".