XLink Example
Let's learn some basic XLink syntax by studying an example.
XML Example Document
Take a look at the following XML document, "bookstore.xml", which is used to present books:
View the "bookstore.xml" file in your browser bookstore.xml.
In the above example, 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's attributes and features.
xlink:type="simple" can create simple, HTML-like links. You can also specify more complex links (multi-directional links), but for now, we are only using simple links.
The xlink:href attribute specifies the URL to link to, while the xlink:show attribute specifies where to open the link. xlink:show="new" means the link (in this example, an image) will open in a new window.
XLink - Deep Dive
In the above example, we only demonstrated simple links. XLink becomes more interesting when we need to access resources at remote locations, rather than just standalone pages. In the example, the XLINK attributes in the <description> element show the value as "new". This means the link should open in a new window. We can set the value in XLINK to show attribute "embed". This means the resource should be embedded into the page. You might think this could be another XML document, not just an image, and you could build an example of a hierarchical structure in an XML document.
With XLink, you can also specify when a resource should be displayed. This is handled by the XLink's actuate attribute. XLINK:actuate="onLoad" specifies that the resource file 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 setups.