XML XLink
Create hyperlinks in XML documents
🔗 What is XLink?
XLink (XML Linking Language) creates hyperlinks in XML documents. Unlike HTML links, XLink supports advanced linking features like multi-directional links and links to multiple resources simultaneously.
<link xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:type="simple"
xlink:href="page.xml">
Click here
</link>
Key XLink Concepts
Simple Links
Basic one-way hyperlinks
xlink:type="simple"
Extended Links
Multi-directional linking
xlink:type="extended"
Locators
Point to resources
xlink:href="url"
Arcs
Define traversal rules
xlink:type="arc"
🔹 Simple XLink
Simple links are the most common XLink type, similar to HTML anchor tags. They create one-way links from one resource to another. The xlink:href attribute specifies the destination, and xlink:show controls how the link opens.
<?xml version="1.0"?>
<document xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Basic simple link -->
<reference xlink:type="simple"
xlink:href="https://example.com/page.xml">
Visit our page
</reference>
<!-- Link with title -->
<reference xlink:type="simple"
xlink:href="document.xml"
xlink:title="Related Document">
See related content
</reference>
</document>
Attributes:
xlink:type - Link type (simple)
xlink:href - Target URL
xlink:title - Link description
🔹 XLink Attributes
XLink provides several attributes to control link behavior and appearance. These attributes define how links are displayed, when they activate, and how they behave when clicked. Understanding these attributes helps create more interactive XML documents.
<link xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:type="simple"
xlink:href="target.xml"
xlink:show="new"
xlink:actuate="onRequest"
xlink:title="Click to view"
xlink:role="http://example.com/linkrole">
Link Text
</link>
Common Attributes:
xlink:show - "new" (new window), "replace" (same window), "embed"
xlink:actuate - "onRequest" (click), "onLoad" (automatic)
xlink:role - Describes link purpose
🔹 Extended Links
Extended links allow complex multi-resource linking that goes beyond simple one-to-one connections. They can link multiple documents together and define various traversal paths between resources, useful for creating document networks.
<extendedLink xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:type="extended">
<!-- Define resources -->
<locator xlink:type="locator"
xlink:href="doc1.xml"
xlink:label="document1"/>
<locator xlink:type="locator"
xlink:href="doc2.xml"
xlink:label="document2"/>
<!-- Define arc (traversal) -->
<arc xlink:type="arc"
xlink:from="document1"
xlink:to="document2"/>
</extendedLink>
🔹 Practical XLink Example
This example shows how to use XLink in a real-world scenario, creating a bibliography with links to external resources. Each citation includes metadata and a link to the full document.
<?xml version="1.0"?>
<bibliography xmlns:xlink="http://www.w3.org/1999/xlink">
<citation>
<title>XML Fundamentals</title>
<author>John Smith</author>
<fulltext xlink:type="simple"
xlink:href="http://example.com/xml-fundamentals.pdf"
xlink:show="new"
xlink:title="Download PDF">
View Full Document
</fulltext>
</citation>
<citation>
<title>Advanced XLink</title>
<author>Jane Doe</author>
<fulltext xlink:type="simple"
xlink:href="http://example.com/advanced-xlink.xml"
xlink:show="replace">
Read Online
</fulltext>
</citation>
</bibliography>
🔹 XLink vs HTML Links
While HTML links are simple and widely supported, XLink offers more flexibility and power for XML documents. XLink supports bidirectional links, multiple destinations, and metadata about relationships between documents.
<!-- HTML Link -->
<a href="page.html">Click here</a>
<!-- XLink Simple -->
<link xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:type="simple"
xlink:href="page.xml"
xlink:show="new"
xlink:actuate="onRequest">
Click here
</link>
XLink Advantages:
✓ Multi-directional links
✓ Link to multiple resources
✓ Rich metadata support
✓ Flexible behavior control