阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

XPointer 实例概述

30次阅读
没有评论

共计 1870 个字符,预计需要花费 5 分钟才能阅读完成。

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

XPointer 实例概述

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

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

目标 XML 文档

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

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

注意上面的 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 来引用:

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

阿里云 2 核 2G 服务器 3M 带宽 61 元 1 年,有高配

腾讯云新客低至 82 元 / 年,老客户 99 元 / 年

代金券:在阿里云专用满减优惠券

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2024-07-25发表,共计1870字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中