XLink Example
Let us learn some basic XLink syntax by studying an example.
XML example document
Look at the following XML document, "bookstore.xml", which presents books:
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.......
xlink:type="simple" xlink:href="http://book.com/images/XQuery.gif" xlink:show="new"> XQuery Kick Start delivers a concise introduction to the XQuery standard.......
View "bookstore.xml" in your browser bookstore.xmlfiles.
In the example above, the XLink document namespace (xmlns:xlink="http://www.w3.org/1999/xlink") is declared at the top of the document. This means the document can access XLink attributes and features.
xlink:type="simple" creates a simple HTML-like link. You can also specify more complex links (multi-directional links), but for now we only use simple links.
The xlink:href attribute specifies the URL to link to, while xlink:show specifies where to open the link. xlink:show="new" means the link (in this case an image) opens in a new window.
XLink - A closer look
In the example above we only showed simple links. XLink becomes more interesting when we want to access resources at remote locations rather than separate pages. In the example above
With XLink you can also specify when a resource should be displayed. This is handled by the XLink actuate attribute. xlink:actuate="onLoad" specifies that the resource should be loaded and displayed. xlink:actuate="onRequest" means the resource cannot be read or displayed until the link is clicked. This is very convenient for low-bandwidth settings.