XLink Example

Let's learn some basic XLink syntax by studying an example

XML instance document

Please see the following XML document, "bookstore.xml", which is used to present books:

<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore xmlns:xlink="http://www.w3.org/1999/xlink">
<book title="Harry Potter">
  <description
  xlink:type="simple"
  xlink:href="http://book.com/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="http://book.com/images/XQuery.gif"
  xlink:show="new">
  XQuery Kick Start provides a concise introduction
  to the XQuery standard......
  </description>
</book>
</bookstore>

View "bookstore.xml" file in your browser.

In the above example, the XLink document namespace is declared at the top of the document:

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

This means that the document is accessible to the properties and features of XLink.

xlink:type="simple" can create simple links similar to HTML. You can also specify more complex links (multi-directional links), but currently, we only use simple links.

The xlink:href attribute specifies the URL to be linked, while the xlink:show attribute specifies where to open the link. xlink:show="new" means that the link (in this case, an image) will open in a new window.