XLink is a W3C specification language which creates internal and external links in the XML documents. The elements of an XML document can behave like a link. In HTML <a>…</a> tag is used to define links. However, in XML, any element can be used as hyperlink.

XLink provides two types of linking simple links and extended links. The links cannot be viewed in browsers.

Syntax for XLink:

<?xml version=”1.0” encoding=”UTF-8”?>

<earth xmlns:xlink=” http://www.w3.org/1999/xlink”>

      <country xlink:type=”simple” xlink:href=”http://www.google-earth”>Earth</country>

</earth>

Where,

  • type refers to the type of link. It can be simple or extended links.
  • href refers to the URL to the link.
  • xlink refers to the xlink namespace.

Simple links

A simple link provides an unidirectional hyperlink from one element to another through URI. It’s syntax looks like the example given above. Simple links are supported in specifications like SVG, RDDL, METS …etc.

Extended links

Extended links allow multiple resources to be linked to an element. An extended link has multiple arcs, where arcs are links with to’ and ‘from nodes defined. An arc has information on the link types, role of each resource mapped… etc. Extended links are not widely supported, but is used in few specifications like XBRL.

Example of XLink extended links

<?xml version=”1.0” encoding=”UTF-8”?>

<earth xmlns:xlink=” http://www.w3.org/1999/xlink” xlink:type=”extended”>

<country xlink:type=”locator” xlink:role=”country” xlink:href=”earth_data.xml”>

<influence xlink:type=”locator” xlink:label=”location” xlink:href=”Russia.xml”/>

<influence xlink:type=”locator” xlink:label=”location” xlink:href=”Moscow.xml”/>

<bind xlink:type=”arc” xlink:from=”country” xlink:to=”location”>

</earth>

 

›› go to examples ››