现在的位置: 首页 > 综合 > 正文

XLink教程[转]

2012年04月25日 ⁄ 综合 ⁄ 共 12265字 ⁄ 字号 评论关闭

XLink教程

XML链接可以分成2部分:XLink 和 XPointer.
XLink定义了在XML文件中创建超链接的标准方式,XPointer允许在XML文件中超链接链接到更多的精确详细部分(碎片)。

内容目录

XLink 和 XPointer 的介绍
This chapter explaines what the XLink and XPointer languages are.
介绍了什么是XLink和XPointer语言

XLink 和 XPointer 语法
The syntax of XLink and XPointer.
有关XLink和XPointer的语法

XLink 实例
An example of using XLink in an XML document.
一个在XML文档中使用了XLink的举例

XPointer 实例
An example of using XLink and XPointer in an XML document.
一个在XML文档中使用了XLink和XPointer的举例

XLink 摘要
This chapter contains a summary on what you have learned in this tutorial and a recommendation on what subject you should study next.
回顾本章所学的内容并给下一步学习提供建议

XLink 参考
XLink attribute reference.
XLink的属性参考

XLink介绍
w3pop.com / 2006-09-21

Xlink/Xpointer 语法

XLink defines a standard way of creating hyperlinks in XML documents.
XLink 定义了一个在XML文件中创建超链接的标准方式。

XPointer allows the hyperlinks to point to more specific parts (fragments) in the XML document.
XPointer允许XML文件中的超链接指向更多精确详细的部分(片断)。


What You Should Already Know
一些你应该知道的知识:

Before you continue you should have a basic understanding of the following:
在你继续看下去之前,你应该先掌握一些基本知识:

  • HTML / XHTML
  • XML / XML Namespaces
  • XPath

If you want to study these subjects first, find the tutorials on our Home page.
如果你想先学这些,那请在我们的Home page(主页)上看一下教程。


What is XLink?
什么是XLINK?

  • XLink is short for the XML Linking Language
    • XLink是XML Linking Language的简称。
  • XLink is a language for creating hyperlinks in XML documents
    • XLink是创建XML文件中超链接的语言。
  • XLink is similar to HTML links - but it is a lot more powerful
    • XLink和HTML链接比较相似-但它功能更强大。
  • ANY element in an XML document can behave as an XLink
    • XML文件中的ANY元素可以XLink的形式表现出来……
  • XLink supports simple links (like HTML) and extended links (for linking multiple resources together)
    • XLink支持如HTML的简单链接和扩展链接(主要是为了共同链接多种资源)
  • With XLink, the links can be defined outside of the linked files
    • 通过XLink,链接可以是被链接文件外部的XLink。
  • XLink is a W3C Recommendation
    • XLink是W3C推荐使用的标准。

What is XPointer?
什么是XPointer?

  • XPointer is short for the XML Pointer Language
    • XPointer是XML Pointer Language的简称。
  • XPointer allows the hyperlinks to point to specific parts of the XML document
    • XPointer允许超链接指向XML文件的细节部分。
  • XPointer uses XPath expressions to navigate in the XML document
    • XPointer通过XPath表达式在XML文件中来实行操作
  • XPointer is a W3C Recommendation
    • XPointer是W3C推荐使用的标准

XLink and XPointer are W3C Recommendations
XLink and XPointer是W3C推荐使用的标准

The XML Linking Language (XLink) became a W3C Recommendation 27. June 2001.
XML链接语言(XLink)在2001年6月27号成为W3C推荐使用的标准。

The XML Pointer Language (XPointer) became a W3C Recommendation 25. March 2003.
XML指示语言(XPointer)在2003年3月25号成为了W3C推荐使用的标准。

You can read more about XML standards in our W3C tutorial.
你可以在我们W3C tutorial(W3C教程)上了解更多XML标准。


XLink and XPointer Browser Support
XLink and XPointer浏览器支持

The browser support for XLink and XPointer is minimal.
浏览器为XLink and XPointer提供了最小限度的支持。

There is some XLink support in Mozilla 0.98+, Netscape 6.02+, and Internet Explorer 6.0. Earlier versions of all of these browsers have no XLinks support at all!
在Mozilla 0.98+, Netscape 6.02+中是支持一些LXink的,但在 Internet Explorer 6.0.早期浏览器版本中是根本没有XLinks的!

Xlink/Xpointer 语法
w3pop.com / 2006-09-21

XLink介绍 XLink 实例

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的属性定义了类型和链接属性(来自XPink命名空间)。

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"创建了一个简单,two-ended 链接(意思是"click from here to go there"从这儿点击到那儿)。过后我们会看一下multi-ended(多重方向)连接。


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就显得比较有用了。在这种方面,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"rock"来指向列表中的第五条款。

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

XLink 实例
w3pop.com / 2006-09-21

Xlink/Xpointer 语法 XPointer 实例

Let's try to learn some basic XLink syntax by looking at an example.
现在就让我们通过实例来学习一下基本的XLink语法。


The XML Example Document
XML实例文件

Look at the following XML document, "bookstore.xml", that represents a few books:
看一下下面出现在一些书里面的 "bookstore.xml"的XML文件:

<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore xmlns:xlink="http://www.w3.org/1999/xlink">
<book title="Harry Potter">

  <description
  xlink:type="simple"
  xlink:href="http://book.com/images/HPotter.gif"
  xlink:show="new">
  As his fifth year at Hogwarts School of Witchcraft and
  Wizardry approaches, 15-year-old Harry Potter is.......
  </description>
</book>
<book title="XQuery Kick Start">
  <description
  xlink:type="simple"
  xlink:href="http://book.com/images/XQuery.gif"
  xlink:show="new">
  XQuery Kick Start delivers a concise introduction
  to the XQuery standard.......
  </description>

</book>
</bookstore>

View the "bookstore.xml" file in your browser
在你的浏览器中查看"bookstore.xml"文件

In the example above the XLink namespace is declared at the top of the document (xmlns:xlink="http://www.w3.org/1999/xlink"). This means that the document has access to the XLink attributes and features.
在上面的实例中,XLink命名空间是声明在文件的最顶端的(xmlns:xlink="http://www.w3.org/1999/xlink")。这就意味着文件有权使用XLink属性和方法。

The xlink:type="simple" creates a simple "HTML-like" link. You can also specify more complex links (multidirectional links), but for now, we will only use simple links.
xlink:type="simple"创建了一个简单"HTML-like"链接。你也可以指定更多的复杂链接(多种方向链接),但是目前我们只会使用简单的链接。

The xlink:href attribute specifies the URL to link to, and the xlink:show attribute specifies where to open the link. xlink:show="new" means that the link (in this case, an image) should open in a new window.
xlink:href属性详细说明了要链接的URI,xlink:show属性详细说明了到哪儿去打开链接。xlink:show="new"的意思是:链接(比如:一个图像)应该在一个新的窗口中打开。


XLink - Going Further
XLink-走得更远更深

In the example above we have only demonstrated simple links. XLink is getting more interesting when we want to access remote locations as resources, instead of standalone pages. The <description> element in the example above sets the value of the xlink:show attribute to "new". This means that the link should open in a new window. We could have set the value of the xlink:show attribute to "embed". This means that the resource should be processed inline within the page. When you consider that this could be another XML document and not just an image, you could, for example, build a hierarchy of XML documents.
在上面的实例中我们只知道示范的简单例子。当我们在资源中想访问比较远的区域(不单单是静止页面)时,XLink就会变得更加有趣。在上面实例中的<description>元素设置了xlink:show属性值为“new”。这意味着链接会在一个新窗口中打开。我们可以设置xlink:show的属性值为 "embed"。这就意味着这些资源将在页面内部逐行处理。比如,当你觉得这个是另外一个XML文件而且不仅仅是一张图片时,可以建立一个XML层级文件。

With XLink, you can also specify WHEN the resource should appear. This is handled by the xlink:actuate attribute. xlink:actuate="onLoad" specifies that the resource should be loaded and shown when the document loads. However, xlink:actuate="onRequest" means that the resource is not read or shown before the link is clicked. This is very handy for low-bandwidth settings.
通过XLink,你也可以指定资源出现的时间。这可以让xlink:actuate属性来处理。xlink:actuate="onLoad"详细说明了当文件载入时资源也要加载并显示。当然,xlink:actuate="onRequest意味着在链接被点击之前,不能阅读或显示资源。这对是窄带(带宽很小的网络)设置来说,是非常便利的。

XPointer 实例
w3pop.com / 2006-09-21

XLink 实例 Xlink 摘要

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 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

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.
XPointer不连接到完整的文件(以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>

Xlink 摘要
w3pop.com / 2006-09-21

XPointer 实例 XLink 参考

XLink Summary
XLink概要

This tutorial has taught you a standard way of creating hyperlinks in XML documents.
这份指南是让大家学会如何在XML文件中创建超链接的标准方式。

You have learned that linking in XML is divided into two parts: XLink and XPointer.
你已经知道了XML链接可以分成2部分:XLink 和 XPointer.

XLink defines a standard way of creating hyperlinks in XML documents and XPointer allows the hyperlinks to point to more specific parts (fragments) in the XML document.
XLink定义了在XML文件中创建超链接的标准方式,XPointer允许在XML文件中超链接链接到更多的精确详细部分(碎片)。

For more information on XLink, please look at our XLink Reference.
如想了解XLink更多信息,请先阅读XLink Reference。


Now You Know XLink, What's Next?
现在你已经知道了XLink,那接下来该了解一些别的了。

The next step is to learn about XQuery.
下一步我们来学习XQuery。

XQuery

XQuery is about querying XML data.
XQuery:查询XML数据。

XQuery is designed to query anything that can appear as XML, including databases.
XQuery是设计用来查询任何以XML形式(包括数据库)出现的文件。

If you want to learn more about XQuery, please visit our XQuery tutorial.
如果你想了解了解XQuery,请访问我们的XQuery tutorial.

XLink 参考
w3pop.com / 2006-09-21

Xlink 摘要

XLink Attribute Reference
XLink属性参考

Attribute
元素
Value
Description
描述
xlink:actuate onLoad
onRequest
other
none
Defines when the linked resource is read and shown
当被连接的资源被读取以及现实的时候定义
xlink:href URL The URL to link to
定义URL链接
xlink:show embed
new
replace
other
none
Where to open the link. Replace is default
定义在哪里打开连接。默认属性为Replace。
xlink:type simple
extended
locator
arc
resource
title
none
The type of link
定义连接类型。

抱歉!评论已关闭.