XLink 是一種基於屬性的語法,用來在 XML 文件中加入連結。它可以是單向的(如 HTML 中的 A 元素),也可以是雙向的——能在兩個方向上連結兩篇文件,因此既能從 A 到 B,也能從 B 到 A。
每個 XLink 元素必須具有一個 xlink:type 屬性,用來指出連結類型;屬性 xlink:href 則指向所欲連結資源的 URI。以下是一個簡單範例:
test XMLns:xlink="https://www.w3.org/1999/xlink"
xlink:type="simple"
xlink:href="https://www.ringkee.com/XML.html">
author Jims /author
date 2005/02/18 /date
/test
xlink:type 屬性共有六種:simple、extended、locator、arc、title、resource。
xlink:show 屬性告訴瀏覽器或應用程式「激活時應該做什麼」,有五種可能的動作。
xlink:actuate 屬性則告訴瀏覽器「何時顯示」,有四種可能值。
一個作用等同 HTML A 元素的連結:
test ... xlink:type="simple"
xlink:href="https://www.ringkee.com/XML.html"
xlink:actuate="onRequest" xlink:show="replace">... /test
一個在頁面嵌入圖片的例子:
image xlink:type="simple"
xlink:actuate="onLoad" xlink:show="embed"
xlink:href="https://www.ringkee.com/flower.png"
width="320" height="240"/
其中 xlink:actuate 與 xlink:show 是可選的;而 xlink:title 與 xlink:role 則用來指定資源之間的描述——title 包含少量描述文字,role 則用 URI 指向較長的描述。