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

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

XLink/XPointer 中的 XLink 实例


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

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" 意味着:在链接被点击之前,不允许阅读或显示资源。这对窄带(带宽很小的网络环境)配置来说,是非常实用的。

评论 (0) All

登陆 | 还没注册?