当前位置: 首页 > 网络学院 > XML相关教程 > XLink/XPointer > XPointer 实例

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

XLink/XPointer 中的 XPointer 实例


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

Let's try to learn some basic XPointer syntax by looking at an example.
讲了这么多,还是让我们通过一些实例来学习一些基本的XPointer语法吧。


XPointer Example
XPointer 实例

In this example, we will show you how to use XPointer in conjunction with XLink to point to a specific part of another document.
在这个实例中,我们会给你展示如何通过XPointer与XLink来指向其它文档中的一段具体部分。

We will start by looking at the target XML document (the document we are going to link to).
我们会通过查阅目标XML文件(我们准备链接的文档)开始我们的学习。


The Target XML Document
目标XML文档

The target XML document is called "dogbreeds.xml" and it lists a few different dog breeds:
目标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>

View the "dogbreeds.xml" file in your browser
在你的浏览器中查阅“dogbreeds.xml”的文件

Note that the XML document above uses id attributes on each element we may want to link to!
注意上面的XML文档,它在每个我们希望链接的元素上使用了ID属性!


The Linking XML Document
链接XML文档

Instead of linking to the entire document (as with XLink), XPointer allows you to link to specific parts of the document. To link to a specific part of a page, add a number sign (#) and an XPointer expression after the URL in the xlink:href attributes.
与XLink链接到完整的文档不同的是,XPointer允许你链接到文档中的具体指定的部分。如果你希望链接到页面的某个精确部分,就需要在 xlink:href 属性的URI中添加一个“#”和“XPointer”表达式。

The expression: #xpointer(id("Rottweiler")) refers to the element in the target document, with the id value of "Rottweiler".
表达式:#xpointer(id("Rottweiler")) 通过 "Rottweiler" 的ID值引用了目标文档中元素。

So the xlink:href attribute would look like this: xlink:href=http://dog.com/dogbreeds.xml#xpointer(id('Rottweiler'))
因此,xlink:href 的属性如下:xlink:href=http://dog.com/dogbreeds.xml#xpointer(id('Rottweiler'))

However, XPointer allows a shorthand form when linking to an element with an id. You can use the value of the id directly, like this: xlink:href=http://dog.com/dogbreeds.xml#Rottweiler
当然,当链接到一个包含ID的元素时,XPointer允许使用缩写格式。你可以直接使用ID值,如:xlink:href=http://dog.com/dogbreeds.xml#Rottweiler

The following XML document refers to information of the dog breed for each of my dogs :-), all through XLink and XPointer references:
下述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>

评论 (0) All

登陆 | 还没注册?