XML - XLink
XLink defines a standard way of creating hyperlinks in XML documents.
What is XLink?
In HTML, we know (and all the browsers know!) that the <a> element defines a hyperlink. However, this is not how it works with XML. In XML documents, you can use whatever element names you want - therefore it is impossible for browsers to predict what hyperlink elements will be called in XML documents.
The solution for creating links in XML documents was to put a marker on elements that should act as hyperlinks.
Below is a simple example of how to use XLink to create links in an XML document:
To get access to the XLink attributes and features 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 the xlink:href attributes in the <homepage> elements define that the type and href attributes come from the xlink namespace.
The xlink:type="simple" creates a simple, two-ended link (means "click from here to go there"). We will look at multi-ended (multidirectional) links later.
XLink is a W3C Recommendation
The XML Linking Language (XLink) became a W3C Recommendation 27. June 2001.
XLink Browser Support
There is no browser support for XLink. But XLink is used in SVG and other XML languages.
An XML Example Document
Look at the following XML document, "bookstore.xml", that represents a few books:
<book title="Harry Potter">
As his fifth year at Hogwarts School of Witchcraft and
Wizardry approaches, 15-year-old Harry Potter is.......
<book title="XQuery Kick Start">
XQuery Kick Start delivers a concise introduction
to the XQuery standard.......
In the example above the XLink namespace is declared at the top of the document (xmlns:xlink="http://www.w3.org/1999/xlink"). This means that the document has access to the XLink attributes and features.
The xlink:type="simple" creates a simple "HTML-like" link. You can also specify more complex links (multidirectional links), but for now, we will only use simple links.
The xlink:href attribute specifies the URL to link to, and the xlink:show attribute specifies where to open the link. xlink:show="new" means that the link (in this case, an image) should open in a new window.
XLink - Going Further
In the example above we have only demonstrated simple links. XLink is getting more interesting when we want to access remote locations as resources, instead of standalone pages. The <description> element in the example above sets the value of the xlink:show attribute to "new". This means that the link should open in a new window. We could have set the value of the xlink:show attribute to "embed". This means that the resource should be processed inline within the page. When you consider that this could be another XML document and not just an image, you could, for example, build a hierarchy of XML documents.
With XLink, you can also specify WHEN the resource should appear. This is handled by the xlink:actuate attribute. xlink:actuate="onLoad" specifies that the resource should be loaded and shown when the document loads. However, xlink:actuate="onRequest" means that the resource is not read or shown before the link is clicked. This is very handy for low-bandwidth settings.
XLink Attribute Reference
|Defines when the linked resource is read and shown|
|xlink:href||URL||The URL to link to|
|Where to open the link. Replace is default|
|The type of link|
Thank You For Helping Us!
Your message has been sent to W3Schools.