XML technologies / XML / XML in a Nutshell / XLinks / Simple links

(Excerpt from "XML in a Nutshell" by Elliotte Rusty Harold & W. Scott Means)

A simple link defines a one-way connection between two resources. Its source, or starting resource is the link element itself. Its destination, or ending resource is identified by a URI (Uniform Resource Identifier). The link runs from the starting resource to the ending resource. The starting resource is always an XML element. The ending resource may be an XML document, an element, a group of elements, a text range within XML, or something outside XML, such as an MPEG movie or PDF file. The URI need not be a URL; it might identify a book by ISBN, for example urn:isbn: 1565922247).

A simple XLink is encoded as an element of any type with an xlink:type attribute with value simple and an xlink:href attribute whose value is the link target’s URI. The prefix xlink must be bound to the namespace URI "http://www.w3.org/1999/xlink". As always, the prefix may change as long as the URI remains the same. Suppose this roman element appears in a children’s literature list and we want to link it to the novel’s text at ftp://archive.org/pub/etext/etext93/wizoz10.txt:

<roman>
   <titel>The Wonderful Wizard of Oz</titel>
   <autor>L. Frank Baum</autor>
   <jahr>1900</jahr>
</roman>

We give the element roman an xlink:type attribute with value simple, an xlink:href attribute containing the target URL and an xmlns:xlink attribute binding the prefix xlink to the namespace URI "http://www.w3.org/1999/xlink", as follows :

<roman xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="ftp://archive.org/pub/etext/etext93/wizoz10.txt">
   <titel>The Wonderful Wizard of Oz</titel>
   <autor>L. Frank Baum</autor>
   <jahr>1900</jahr>
</roman>

This creates a simple link from this roman element to the text file at ftp://archive.org/pub/etext/etext93/wizoz10.txt. Browsers may interpret this link as they choose. The most natural interpretation, implemented by the few browsers supporting simple XLinks, displays a blue underlined phrase that users click to replace the current page with the linked file. Other approaches are possible.

XLinks are fully namespace-aware. The conventional prefix is xlink, but another may be used. It must, however, be bound to the URI "http://www.w3.org/1999/xlink". This binding may appear on the XLink element itself, as in this roman example, or on an ancestor up to the document’s root element. Later examples in this and the next chapter use only the xlink prefix, assuming it has been correctly declared on an earlier element.

Every XLink element must have an xlink:type attribute specifying the link type or part of a link. It has six possible values:

Simple XLinks (simple) are the only ones closely resembling HTML links. The other five types of XLink elements are covered on the following pages.

The attribute xlink:href identifies the referenced resource and always contains a URI. As with HTML links, relative and absolute URLs are allowed, but the URI need not be a URL. For example, this link identifies the printed edition of The Wonderful Wizard of Oz with ISBN 0688069444, without assigning it a location:

<roman xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="urn:isbn:0688069444">
   <titel>The Wonderful Wizard of Oz</titel>
   <autor>L. Frank Baum</autor>
   <jahr>1900</jahr>
</roman>

  

 

 

 

back to top