X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

XML - XLink


XLink (the XML Linking language) defines methods for creating links within XML documents.


What is XLink?

XPath
  • XLink is used to create hyperlinks within XML documents
  • Any element in an XML document can behave as a link
  • XLink supports simple links (like HTML) and extended links (for linking multiple resources together)
  • With XLink, the links can be defined outside the linked files
  • XLink is a W3C Recommendation


XLink Syntax

In HTML, the <a> element defines a hyperlink. However, this is not how it works in XML. In XML documents, you can use whatever element names you want - therefore it is impossible for browsers to predict what link elements will be called in XML documents.

Below is a simple example of how to use XLink to create links in an XML document:

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

<homepages xmlns:xlink="http://www.w3.org/1999/xlink">
  <homepage xlink:type="simple" xlink:href="http://www.w3schools.com">Visit W3Schools</homepage>
  <homepage xlink:type="simple" xlink:href="http://www.w3.org">Visit W3C</homepage>
</homepages>

To get access to the XLink features we must declare the XLink namespace. The XLink namespace is: "http://www.w3.org/1999/xlink".

The xlink:type and the xlink:href attributes in the <homepage> elements come from the XLink namespace.

The xlink:type="simple" creates a simple "HTML-like" link (means "click here to go there").

The xlink:href attribute specifies the URL to link to.


XLink Browser Support

There is no browser support for XLink in XML documents. However, all major browsers support simple XLinks in SVG.


XLink Example

The following XML document contains XLink features:

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

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

<book title="Harry Potter">
  <description
  xlink:type="simple"
  xlink:href="/images/HPotter.gif"
  xlink:show="new">
  As his fifth year at Hogwarts School of Witchcraft and
  Wizardry approaches, 15-year-old Harry Potter is.......
  </description>
</book>

<book title="XQuery Kick Start">
  <description
  xlink:type="simple"
  xlink:href="/images/XQuery.gif"
  xlink:show="new">
  XQuery Kick Start delivers a concise introduction
  to the XQuery standard.......
  </description>
</book>

</bookstore>

Example explained:

  • The XLink namespace is declared at the top of the document (xmlns:xlink="http://www.w3.org/1999/xlink")
  • The xlink:type="simple" creates a simple "HTML-like" link
  • The xlink:href attribute specifies the URL to link to (in this case - an image)
  • The xlink:show="new" specifies that the link should open in a new window

XLink - Going Further

In the example above we have demonstrated simple XLinks. XLink is getting more interesting when accessing remote locations as resources, instead of standalone pages.

If we set the value of the xlink:show attribute to "embed", the linked resource should be processed inline within the page. When you consider that this could be another XML document you could, for example, build a hierarchy of XML documents.

You can also specify WHEN the resource should appear, with the xlink:actuate attribute.


XLink Attribute Reference

Attribute Value Description
xlink:actuate onLoad
onRequest
other
none
Defines when the linked resource is read and shown:
  • onLoad - the resource should be loaded and shown when the document loads
  • onRequest - the resource is not read or shown before the link is clicked
xlink:href URL Specifies the URL to link to
xlink:show embed
new
replace
other
none
Specifies where to open the link. Default is "replace"
xlink:type simple
extended
locator
arc
resource
title
none
Specifies the type of link



Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook