XLink 实例

让我们通过研究一个实例来学习一些基础的 XLink 语法

XML 实例文档

请看下面的 XML 文档,"bookstore.xml",它用来呈现书籍:

<?xml version="1.0" encoding="ISO-8859-1"?>

<bookstore xmlns:xlink="//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 delivers a concise introduction
  to the XQuery standard.......
  </description>
</book>

</bookstore>

在您的浏览器查看 "bookstore.xml" 文件

在上面的例子中,XLink 文档命名空间被声明于文档的顶部:

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

这意味着文档可访问 XLink 的属性和特性。

xlink:type="simple" 可创建简单的类似 HTML 的链接。您也可以规定更多的复杂的链接(多方向链接),但是目前,我们仅使用简易链接。

xlink:href 属性规定了要链接的 URL,而 xlink:show 属性规定了在何处打开链接。xlink:show="new" 意味着链接(在此例中,是一幅图像)会在新窗口打开。