Presentation is loading. Please wait.

Presentation is loading. Please wait.

McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Linking XML Documents Ellen Pearlman Eileen Mullin Programming the Web.

Similar presentations


Presentation on theme: "McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Linking XML Documents Ellen Pearlman Eileen Mullin Programming the Web."— Presentation transcript:

1 McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Linking XML Documents Ellen Pearlman Eileen Mullin Programming the Web Using XML

2 9-2 Learning Objectives 1.Learn how to use XLink to link between XML documents and specific parts within them 2.See how both single-direction links like those in HTML documents and multi- directional links can be added to XML documents 3.Define XLink elements in an XML DTD 4.Use XPointer to point to any part of a target document on local or remote Web servers

3 9-3 Introduction to Linking in XML Documents XLink lets you insert elements into XML documents in order to create links between XML documents. XPointer provides a way to link into the internal structures of XML documents, including elements, attributes, and actual content.

4 9-4 Introducing XML Linking Language (XLink) With the XML Linking Language, or XLink, you can add elements within XML documents that create and link not only to other XML documents, but also to many components that might appear in an XML document, such as images, query results, or even other types of files or applications. The syntax used by XLink is reminiscent of HTML in many respects: Index

5 9-5 Hyperlinking Within HTML Documents

6 9-6 Hyperlinking Within XML Documents

7 9-7 Traversal and Linkbases All of the details about what happens when a link is followed – or a resource is accessed – using XLink comes under the comprehensive term traversal. Another useful XLink benefit is that you can create a collection of links for a series of documents in an ongoing database, known as a linkbase, which can be filtered or sorted as you desire.

8 9-8 Linking Elements To create XLink-based links, you need to define a linking element, which is an XML element recognized as having linking powers. There are two types of linking elements you can create with Xlink: –Simple links are designed to point to one target page only. –Extended links essentially offer a fork in the road: you could visit one of multiple potential destination pages.

9 9-9 Types of XLink Elements XLink elements can be one of six different types. Two of them are the linking elements (simple and extended) described previously. The other four elements let you construct a kind of “smart link.” These include: –locator –resource –arc –title

10 9-10 Global Attributes XLink provides global attributes that you use to declare your links’ details and special qualities. These include: –type –href –role –arcrole –title –show –actuate –label –from –to

11 9-11 Sample Simple Link <publisher xmlns:xlink="http://www.w3.org/1999/xlink/" xlink:type="simple" xlink:href="http://www.mcgraw-hill.com/about/about.html" xlink:show="new" xlink:actuate="onRequest" >About McGraw-Hill

12 9-12 Using XLink to Link to an Object <my-image xmlns:xlink="http://www.w3.org/1999/xlink/" xlink:type="simple" xlink:href=" http://pics.ebay.com/aw/pics/ebay_my_button.gif" xlink:show="embed" xlink:actuate="onLoad" />

13 9-13 Using XLink to Link to an External File <imported-legal xmlns:xlink="http://www.w3.org/1999/xlink/" xlink:type="simple" xlink:href="http://www.genuineclass.com/xml/legalese.html" xlink:show="onLoad" xlink:actuate="embed" />

14 9-14 Extended Links An extended link is intended to link to any number of resources. It defines a set of arcs – containing information about where links are used and where they should go – between several resources. Extended links are most important in situations where the participants have access to the resources under discussion. Another potential use is when the resources appear in formats that don’t typically allow for clickable, embedded links – for example, audio or video files.

15 9-15 Remote Resources Connected Through an Extended Link

16 9-16 Extended-Type Elements and Their Child Elements The extended-type element can contain child elements with any of the following type attributes: –locator-type elements, which list what remote resources are participating in the link –arc-type elements, which provide traversal rules among the link’s participating resources –title-type elements, which apply labels to make it easy for people to understand what each link is for –resource-type elements, which indicate the local resources that participate in the link

17 9-17 Creating XLinks in DTDs Start by declaring a straightforward simple link element in a DTD. It appears as an !ATTLIST component specifically because it is within a DTD : <!ATTLIST schedule xmlns:xlinkCDATA#FIXED "http://www.w3.org/1999/xlink" xlink:type(simple)#FIXED "simple" xlink:hrefCDATA#IMPLIED xlink:show(new)#FIXED "new" xlink:actuate(onRequest)#FIXED "onRequest"> In your XML document, you might add a link as follows: Current class schedule

18 9-18 Introducing XPointer While XLink can be very useful, as you've seen, it only lets you refer to another document. It’s likely that you may want to refer to a specific part within another document. XPointer allows you to do this with a capability similar to the concept of named anchors in HTML pages. This is especially useful for search engines, and in cataloging large documents.

19 9-19 A Sample XPointer Elements can have an ID attribute, which is meant to be used for linking and pointing: An XPointer that specifically points to the W3C Notes entry on the W3C’s Technical Reports and Publications page – where The ID assigned to this section is "Notes” – would appear as follows: http://www.w3.org/TR/#xpointer(id('Notes'))

20 9-20 Linking with XPointer

21 9-21 Caveats to Bear in Mind When Linking With XPointer The resource you link to must be an XML document. The resource must remain online. The ID must not change. If the value of the element’s ID attribute changes, any links you've made using XPointer would need to be updated in kind; otherwise, the link will not work correctly. The application has to support XPointers. Browser support for XPointer has plodded along even further behind that for XLink.

22 9-22 Location Paths XPath lets you locate a node (elements or character data), or set of nodes, at any level of an XML document tree using what's called a location path. A location path can be an absolute path, which describes a location in reference to the root node. Or, a location path could be a relative path, which means you can point to elements that are relative to other elements.

23 9-23 Path to an XPointer Within a sample XML document called filmdb.xml: Raising Arizona 1987 Joel Coen …an XPointer could link directly to the data for "Raising Arizona" via the film's "id" attribute: Raising Arizona

24 9-24 The End


Download ppt "McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Linking XML Documents Ellen Pearlman Eileen Mullin Programming the Web."

Similar presentations


Ads by Google