讓我們通過研究一個實例來學習一些基礎的 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=/uploadfile/2012/0411/20120411052733746.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=/uploadfile/2012/0411/20120411052733127.gif" xlink:show="new"> XQuery Kick Start delivers a concise introduction to the XQuery standard....... </description> </book> </bookstore>
在您的瀏覽器查看 "bookstore.xml" 文件。
在上面的例子中,XLink 文檔命名空間被聲明于文檔的頂部:
xmlns:xlink="http://www.w3.org/1999/xlink"
這意味著文檔可訪問 XLink 的屬性和特性。
xlink:type="simple" 可創建簡單的類似 HTML 的鏈接。您也可以規定更多的復雜的鏈接(多方向鏈接),但是目前,我們僅使用簡易鏈接。
xlink:href 屬性規定了要鏈接的 URL,而 xlink:show 屬性規定了在何處打開鏈接。xlink:show="new" 意味著鏈接(在此例中,是一幅圖像)會在新窗口打開。