XLink 實(shí)例
讓我們通過研究一個(gè)實(shí)例來學(xué)習(xí)一些基礎(chǔ)的 XLink 語法
XML 實(shí)例文檔
請看下面的 XML 文檔,"bookstore.xml",它用來呈現(xiàn)書籍:
<?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> </bookstore>
在上面的例子中,XLink 文檔命名空間被聲明于文檔的頂部:
xmlns:xlink="http://www.w3.org/1999/xlink"
這意味著文檔可訪問 XLink 的屬性和特性。
xlink:type="simple" 可創(chuàng)建簡單的類似 HTML 的鏈接。您也可以規(guī)定更多的復(fù)雜的鏈接(多方向鏈接),但是目前,我們僅使用簡易鏈接。
xlink:href 屬性規(guī)定了要鏈接的 URL,而 xlink:show 屬性規(guī)定了在何處打開鏈接。xlink:show="new" 意味著鏈接(在此例中,是一幅圖像)會在新窗口打開。