XLink 实例
让我们通过研究一个实例来学习一些基础的 XLink 语法
XML 实例文档
请看下面的 XML 文档,"bookstore.xml",它用来呈现书籍:
<?xml version="1.0" encoding="ISO-8859-1"?> <bookstorexmlns:xlink="http://www.w3.org/1999/xlink">
<book title="Harry Potter"> <descriptionxlink: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> IfColor 9,908,"0",0 Then Delay 60 Goto 第一波的不能有这个元素在这下一步30501一 Else Goto 第一波的不能有这个元素在这的跳出来3005一 End If Rem 第一波的不能有这个元素在这下一步30501一 Delay 60 IfColor 20,908,"0",0 Then Delay 60 Goto 第一波的不能有这个元素在这下一步30502一 Else Goto 第一波的不能有这个元素在这的跳出来3005一 End If Rem 第一波的不能有这个元素在这下一步30502一 Delay 60 IfColor 44,908,"0",0 Then Delay 60 Goto 第一波的不能有这个元素在这下一步30503一 Else Goto 第一波的不能有这个元素在这的跳出来3005一 End If Rem 第一波的不能有这个元素在这下一步30503一 Delay 60 IfColor 52,913,"0",0 Then Delay 60 Goto 第一波的不能有这个元素在这下一步30504一 Else Goto 第一波的不能有这个元素在这的跳出来3005一 End If Rem 第一波的不能有这个元素在这下一步30504一 Delay 60 </bookstore>
在上面的例子中,XLink 文档命名空间被声明于文档的顶部:
xmlns:xlink="http://www.w3.org/1999/xlink"
这意味着文档可访问 XLink 的属性和特性。
xlink:type="simple" 可创建简单的类似 HTML 的链接。您也可以规定更多的复杂的链接(多方向链接),但是目前,我们仅使用简易链接。
xlink:href 属性规定了要链接的 URL,而 xlink:show 属性规定了在何处打开链接。xlink:show="new" 意味着链接(在此例中,是一幅图像)会在新窗口打开。