XLink is a specification for enhanced and improved linking capabilities that are designed for use with XML documents. XLink is an acronym for XML Linking Language. It allows XML documents to establish a linking relationship between more than one document and create linking documents that reside in a separate location from the linked documents.
Xpointer is the XML Pointer Linking Language, defines an addressing scheme for the individual parts of an XML document. It can be used by any application that needs to identify a part or location of an XML document.
Syntax for Linking: XLinks are of two types : Simple and Extended
A Simple link is similar to the link created in HTML using the anchor element. SML has no specified set of tags. So any element with a user-defined name can be used to establish a link with another document. Below is a simple example of how to use XLink to create links in an XML document:
<?xml version="1.0"?> <weblinks xmlns:xlink="http://www.w3.org/1999/xlink"> <link xlink:type="simple" xlink:href="http://www.microsoft.com">Visit Microsoft</link> <link xlink:type="simple" xlink:href="http://www.w3.org">Visit W3C</link> <link xlink:type="simple" xlink:href="http://www.coderewind.com">Visit Code Rewind</link> </weblinks>
An Extended link can point to several resources at a time. It can be used to create links to other documents from your document, even if you do not have a write privilege on that document. Extended links are of two types, out-of-the links and multidirectional links.
XLink uses the following attributes for creating single or extended link: href, role, title, show, actuate and type.
The href attribute is used as a resource locator for the link.
<mylink xml:link="extended" xlink:href="http://www.mylink.com"> Click here to go the link. </mylink>
The role attribute provides additional information about the link. For example, an extended link may lhave three documents containing the topic details, suggestions and summary respectively as it’s three targets. The role attribute of this extended link will contain additional information about each of the three different target documents.
<artist xml:link="extended" xlink:href="michealangelo.xml" xlink:role ="michealangelo"> More information on Michealangelo </artist>
The title attribute allows to specify a label to provide information to the user. While the role attribute is meant for the system and the application, the title attribute is meant for providing supplementary information to the user.
<subject xml:link="extended" xlink:href="history.xml" xlink:role ="history" xlink:title =" History Syllabus"> Details of the Revised Syllabus </subject>
The show attribute can take embed, replace or new as its value to specify that the content of the linked object will appear embedded within the document, will replace the document, or appear separately in a new browser window respectively.
The actuate attribute allows to specify timing of the link. It can take two predefined values: OnRequest and OnLoad.
OnRequest specifies that the link should be traversed only when the user clicks on it. Whereas OnLoad specifies the link is traversed once link is loaded. For example, you may set the actuate attribute to OnLoad for an image that is to be embedded in the linking document. This link will be traversed after the image is loaded.
Pointing to a particular part in a document:
XPointer is a new specification designed to link to portions of a document without having to link to the entire document.
Consider the following XML code that contains the catalog of books:
<xml version ="1.0"?> <catalog> <book> <title> ASP.NET </title> <author> MS Press </author> </book> <book> <title> C# Unleashed </title> <author> Microsoft </author> </book> </catalog>
If a link has to be created for the entry of the second book, the code would be: href = “catalog.xml#child(2, book)”