Menu

XLink: An Introductory Example

September 18, 2000

Fabio Arciniegas A.

Table of Contents

Introduction
An Example XLink
XLink Reference
  •The XLink Type Attribute
  •XLink Types: Use and
   Composition
  •Simple Links
Tools and References
Conclusion

Before we start to dissect the structure of XLink, let's examine a concrete example.

The Artist/Influence problem

Suppose you want to express in XML the relationship between artists and their environment. This includes making links from an artist to his/her influences, as well as links to descriptions of historical events of their time. The data for each artist might be written in a file like the following:


   <?xml version="1.0"?>

   <artistinfo> 

    <surname>Modigliani</surname>

    <name>Amadeo</name>

    <born>July 12, 1884</born><died>January 24, 1920</died>

    <biography>

      <p>In 1906, Modigliani settled in Paris, where ...</p>

    </biography>

   </artistinfo>

Also, brief descriptions of time periods are included in separate files such as:


   <?xml version="1.0"?>

   <period> 

    <city>Paris</city>

    <country>France<country>

    <timeframe begin="1900" end="1920"/>

    <title>Paris in the early 20th century (up to the twenties)</title>

    <end>Amadeo</end>

    <description>

      <p>During this period, Russian, Italian, ...</p>

    </description>

   </period>

Fulfilling our requirement (i.e. creating a file that relates artists to their influences and periods) is a task beyond a simple strategy like adding "a" or "img" links to the above documents, for several reasons:

  • A single artist has many influences (a link points from one resource to many).

  • A single artist has associations with many periods.

  • The link itself must be semantically meaningful. (Having an influence is not the same as belonging to a period, and we want to express that in our document!)

The XLink Solution

In XLink we have two type of linking elements: simple (like "a" and "img" in HTML) and extended. Links are represented as elements. However, XLink does not impose any particular "correct" name for your links; instead, it lets you decide which elements of your own are going to serve as links, by means of the XLink attribute type. An example snippet will make this clearer:


   <environment xlink:type="extended">

       <!-- This is an extended link -->

       <!-- The resources involved must be included/referenced here -->

   </environment> 

Now that we have our extended link, we must specify the resources involved. Since the artist and movement information are stored outside our own document (so we have no control over them), we use XLink's locator elements to reference them. Again, the strategy is not to impose a tag name, but to let you mark your elements as locators using XLink attributes:


   <environment xmlns:xlink="http://www.w3.org/1999/xlink" 

       xlink:type="extended">

       <!-- The resources involved in our link are the artist -->

       <!-- himself, his influences and the historical references -->

       <artist    xlink:type="locator" xlink:label="artist" 

             xlink:href="modigliani.xml"/>

       <influence xlink:type="locator" xlink:label="inspiration"

             xlink:href="cezanne.xml"/>

       <influence xlink:type="locator" xlink:label="inspiration"

             xlink:href="lautrec.xml"/>

       <influence xlink:type="locator" xlink:label="inspiration"

             xlink:href="rouault.xml"/>

       <history   xlink:type="locator" xlink:label="period"

             xlink:href="paris.xml"/>

       <history   xlink:type="locator" xlink:label="period"

             xlink:href="kisling.xml"/>

   </environment>

Only one thing is missing: We must specify how the resources relate to each other. We do this by specifying arcs between them:


   <environment xmlns:xlink="http://www.w3.org/1999/xlink" 

        xlink:type="extended">

        <!-- an artist is bound to his influences and history -->

        <artist    xlink:type="locator" xlink:role="artist"

              xlink:href="modigliani.xml"/>

        <influence xlink:type="locator" xlink:label="inspiration"

              xlink:href="cezanne.xml"/>

        <influence xlink:type="locator" xlink:label="inspiration"

              xlink:href="lautrec.xml"/>

        <influence xlink:type="locator" xlink:label="inspiration"

              xlink:href="rouault.xml"/>

        <history   xlink:type="locator" xlink:label="period"

              xlink:href="paris.xml"/>

        <history   xlink:type="locator" xlink:label="period" 

              xlink:href="kisling.xml"/>

        <bind xlink:type="arc" xlink:from="artist"  

              xlink:to="inspiration"/>

        <bind xlink:type="arc" xlink:from="artist"

              xlink:to="period"/>

      </environment>

As you can see, using XLink, our problem is reduced to creating an XML file full of elements like the above, where all the resources and their relationships are clearly and elegantly specified.

In this section we saw a small example of the use and syntax of XLink. In the next one, we will examine in detail the constructs and rules of this linking mechanism.