XLink and XPointer Syntax
XLink and XPointer Syntax
XLink Syntax
In HTML, we know that the <a> element defines hyperlinks. However, XML does not work this way. In an XML document, you can use any name you need β therefore, browsers cannot predict which elements in an XML document can serve as hyperlinks.
To define hyperlinks in an XML document, place markup on elements that can act as hyperlinks.
Here is a simple example of using XLink to create links in an XML document:
<?xml version="1.0"?>
<homepages xmlns:xlink="http://www.w3.org/1999/xlink">
<homepage xlink:type="simple"
xlink:href="#">Visit </homepage>
<homepage xlink:type="simple"
xlink:href="http://www.w3.org">Visit W3C</homepage>
</homepages>
To access XLink attributes and properties, 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-end link (meaning "from here to there"). We will explore multi-end links (multi-directional) later.
XPointer Syntax
In HTML, we can create a hyperlink that points to both a web page and a specific bookmark within that page (using #).
Sometimes, pointing to more specific content is even more useful. For example, we might want to point to the third item in a list or the second line of the fifth paragraph. This is easily achieved using XPointer.
If a hyperlink points to an XML document, we can append the XPointer portion to the URL in the xlink:href attribute, allowing navigation (via XPath expressions) to a specific location within the document.
For example, in the following case, we use XPointer to target the fifth item in a list via the unique ID "rock":
href="http://www.example.com/cdlist.xml#id('rock').child(5,item)"
Share Your Notes
Write Notes...
Category Navigation
ByteArk Coding Plan
Supports mainstream models like Doubao, GLM, DeepSeek, Kimi, MiniMax. Official supply, stable and reliable.
Β₯9.9/month Get Started Now
SparkDesk Coding Plan
Includes free model call quota. DeepSeek, GLM, Kimi, MiniMax β one-stop experience and deployment platform.
Β₯3.9/month Get Started Now
YouTip