Xlink in XML
XLink in XML
What is XLink?
XLink stands for XML Linking Language.
It is a W3C specification used to create hyperlinks in XML documents.
XLink extends XML with the ability to define simple and extended links similar to HTML hyperlinks but more powerful.
Purpose of XLink
To link XML resources.
To enable linking between multiple XML documents or different parts of the same document.
Supports simple links (like HTML anchors) and extended links (multiple resources, arcs).
Types of Links in XLink
Simple Link
Like an HTML hyperlink, connects one resource to another.Extended Link
Allows linking multiple resources together with defined relationships.
Basic Syntax of XLink (Simple Link)
You add an xlink namespace and attributes to elements.
<book xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://example.com/moreinfo.xml"> More Info</book>xlink:type="simple"— defines a simple link.xlink:href— specifies the target URI.
Extended Link Example (Brief)
<link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="extended" xlink:role="http://example.com/role"> <resource xlink:type="resource" xlink:label="r1" xlink:href="doc1.xml"/> <resource xlink:type="resource" xlink:label="r2" xlink:href="doc2.xml"/> <arc xlink:type="arc" xlink:from="r1" xlink:to="r2" xlink:arcrole="related"/></link>Links multiple resources and defines relationships (
arc).
Summary of XLink Attributes
| Attribute | Purpose |
|---|---|
xlink:type | Type of link (simple, extended, resource, locator, arc) |
xlink:href | URI of the linked resource |
xlink:role | Role or purpose of the link |
xlink:arcrole | Role of the arc in extended links |
xlink:label | Label for referencing resources |
When to Use XLink?
When your XML documents need complex linking beyond simple URLs.
In applications like digital libraries, scientific data, and compound documents.
If you want, I can show you how to use XLink in a real XML document or how to parse XLink links programmatically!