良许Linux教程网 干货合集 详解XPointer 实例

详解XPointer 实例

XPointer 是 XML 指针文件(XML Pointer Language)的缩写,XPointer 使超级链接可以指向 XML 文档中更多具体的部分(片断)。

XPointer 实例概述XPointer 实例概述

在本例中,我们会为您展示如何使用 XPointer 并结合 XLink 来指向另外一个文档的某个具体的部分。

我们将通过研究目标 XML 文档开始(即我们要链接的那个文档)。

目标XML文档

目标XML文档名为 “dogbreeds.xml”,它列出了一些不同的狗种类:

"1.0" encoding="ISO-8859-1"?>
"Rottweiler" id="Rottweiler">
"http://dog.com/rottweiler.gif" />
history>The Rottweiler's ancestors were probably Roman
drover dogs.....
Confident, bold, alert and imposing, the Rottweiler
is a popular choice for its ability to protect....One of the earliest uses of retrieving dogs was to
help fishermen retrieve fish from the water....The flat-coated retriever is a sweet, exuberant,
lively dog that loves to play and retrieve....

注意上面的 XML 文档在每个我们需要链接的元素上使用了 id 属性!

XML 链接文档

不止能够链接到整个文档(当使用 XLink 时),XPointer 允许您链接到文档的特定部分。如需链接到页面的某个具体的部分,请在 xlink:href 属性中的 URL 后添加一个井号 (#) 以及一个 XPointer 表达式。

表达式:#xpointer(id(“Rottweiler”)) 可引用目标文档中 id 值为 “Rottweiler” 的元素。

因此,xlink:href 属性会类似这样:xlink:href=”http://dog.com/dogbreeds.xml#xpointer(id(‘Rottweiler’))”

不过,当使用 id 链接到某个元素时,XPointer 允许简写形式。您可以直接使用 id 的值,就像这样:xlink:href=”http://dog.com/dogbreeds.xml#Rottweiler”。

下面的 XML 文档可引用每条狗的品种信息,均通过 XLink 和 XPointer 来引用:

"1.0" encoding="ISO-8859-1"?>
"http://www.w3.org/1999/xlink">
type="simple"
xlink:href="http://dog.com/dogbreeds.xml#Rottweiler">
type="simple"
xlink:href="http://myweb.com/mydogs/anton.gif">
Anton is my favorite dog. He has won a lot of.....
type="simple"
xlink:href="http://dog.com/dogbreeds.xml#FCRetriever">
type="simple"
xlink:href="http://myweb.com/mydogs/pluto.gif">
Pluto is the sweetest dog on earth......

以上就是良许教程网为各位朋友分享的Linu系统相关内容。想要了解更多Linux相关知识记得关注公众号“良许Linux”,或扫描下方二维码进行关注,更多干货等着你 !

137e00002230ad9f26e78-265x300
本文由 良许Linux教程网 发布,可自由转载、引用,但需署名作者且注明文章出处。如转载至微信公众号,请在文末添加作者公众号二维码。
良许

作者: 良许

良许,世界500强企业Linux开发工程师,公众号【良许Linux】的作者,全网拥有超30W粉丝。个人标签:创业者,CSDN学院讲师,副业达人,流量玩家,摄影爱好者。
上一篇
下一篇

发表评论

联系我们

联系我们

公众号:良许Linux

在线咨询: QQ交谈

邮箱: yychuyu@163.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部