当前位置: 首页 > 网络学院 > XML相关教程 > XLink/XPointer > Xlink/Xpointer 语法

XLink/XPointer
XLink介绍
Xlink/Xpointer 语法
XLink 实例
XPointer 实例
Xlink 摘要
XLink 参考

XLink/XPointer 中的 Xlink/Xpointer 语法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 558 ::
收藏到网摘: n/a

XLink Syntax
XLink 语法

In HTML, we know (and all the browsers know!) that the <a> element defines a hyperlink. However, this is not how it works with XML. In XML documents, you can use whatever element names you want - therefore it is impossible for browsers to predict what hyperlink elements will be called in XML documents.
在HTML中,我们知道(并且,所有浏览器都知道!),<a>元素定义了一个超链接。然而,在XML中并不是这样的。在XML文件中,你可以使用任何一个你所设想的元素名称——因此,让浏览器预知XML文件中能被访问的超链接元素是不可能的。

The solution for creating links in XML documents was to put a marker on elements that should act as hyperlinks.
在XML文件中创建链接的具体方法是:为需要执行超链接作用的元素加入一个标记。

Below is a simple example of how to use XLink to create links in an XML document:
下面列举了如何在XML文档中使用XLink创建链接的简易案例:

<?xml version="1.0"?>
<homepages xmlns:xlink="http://www.w3.org/1999/xlink">
<homepage xlink:type="simple"

xlink:href="http://www.w3schools.com">Visit W3Schools</homepage>
<homepage xlink:type="simple"
xlink:href="http://www.w3.org">Visit W3C</homepage>
</homepages>

To get access to the XLink attributes and features we must declare the XLink namespace at the top of the document.
如果你希望使用XLink属性和特性,那就必须在文件顶部声明XLink的命名空间。

The XLink namespace is: http://www.w3.org/1999/xlink.
XLink命名空间是:http://www.w3.org/1999/xlink

The xlink:type and the xlink:href attributes in the <homepage> elements define that the type and href attributes come from the xlink namespace.
<homepage> 元素中的 “xlink:type” 属性和 “xlink:href” 属性定义了来自于XLink命名空间的类型和href属性。

The xlink:type="simple" creates a simple, two-ended link (means "click from here to go there"). We will look at multi-ended (multidirectional) links later.
xlink:type="simple" 创建了一个简单的“双边链接”(“双边链接”的意思是"从这儿点击到那儿")。在后面的内容中,我们会学习“多边连接”。


XPointer Syntax
XPointer 语法

In HTML, we can create a hyperlink that either points to an HTML page or to a bookmark inside an HTML page (using #).
在HTML中,我们可以创建一个任意指向HTML页面或HTML页面内的书签超链接(书签超链接使用#)。

Sometimes it is more useful to point to more specific content. For example, let's say that we want to link to the third item in a particular list, or to the second sentence of the fifth paragraph. This is easy with XPointer.
有时,指向精确的内容会显得更加有效。比如,当我们需要在一张特定的列表里链接第三项或链接到第五段的第二句话时,使用 XPointer 就会使整个过程的实现变得非常简单。

If the hyperlink points to an XML document, we can add an XPointer part after the URL in the xlink:href attribute, to navigate (with an XPath expression) to a specific place in the document.
如果超链接指向XML文档,我们可以在“XLink:href”属性中的URI之后添加一个XPointer部分,从而通过使用XPath表达式使其定位到文档中的具体地方。

For example, in the example below we use XPointer to point to the fifth item in a list with a unique id of "rock":
例如,在下述案例中,我们使用 XPointer 指向id为“lock”列表中的第五条款,具体如下:

href="http://www.example.com/cdlist.xml#id('rock').child(5,item)"

评论 (0) All

登陆 | 还没注册?