1 XLink and XPointer
Outline 1 Introduction 2 XML Linking Language (XLink) 2.1 Simple Links 2.2 Extended Links 3 XLink and DTDs 4 XML Pointer Language (XPointer) 5 XInclude 6 XBase
2002 Prentice Hall, Inc. All rights reserved. 2 1 Introduction
• XLink – Describing links between resources (e.g., documents) • XPointer – “Pointing” to document contents – “address” nodes, ranges, and points • XInclude – Including existing XML document into another • XBase – Specifies “base” URL for relative URLs • XForms – XML-based form-processing mechanism • SVG (uses XLink) – XML-based graphic rendering
2002 Prentice Hall, Inc. All rights reserved. 3 2 XML Link Language (XLink) • XLink – Links “resources” from XML documents • E.g., link documents, audio, video, database data, etc. – Resources accessed through multiple links – More flexible features than Hyperlinks – Simple links or extended links – HTML, HyTime, and text Encoding Initiative (TEI) are the most influential
2002 Prentice Hall, Inc. All rights reserved. 4 2.1 Simple Links • Simple links – Links one resource to another (similar to HTML Hyperlink), it is an inline link. – Linking elements • Specify linking information
2002 Prentice Hall, Inc. All rights reserved. 5 Fig. 1 Illustrating a simple link.
document 1 document 2
2002 Prentice Hall, Inc. All rights reserved. 6 An Sample Simple Link DTD
2002 Prentice Hall, Inc. All rights reserved. 7 1 Outline 2 3 Fig. 2 XML document 4 with a simple link. 5 6
2002 Prentice Hall, Inc. All rights reserved. 9 Output from Fig. 2
2002 Prentice Hall, Inc. All rights reserved. 10 Output from Fig. 2
2002 Prentice Hall, Inc. All rights reserved. 11 1 Outline 2 3 Fig. 3 Listing for 4 . 5 about.xml 6
2002 Prentice Hall, Inc. All rights reserved. 13 Output from Fig. 4
2002 Prentice Hall, Inc. All rights reserved. 14 Output from Fig. 4
2002 Prentice Hall, Inc. All rights reserved. 15 Attributes of XLink
• Type – simple or extended (locator, resource, arc) • Href – remote resource’s URI • Role – URI that references a resource that describes the link (optional) • Title – descriptive title for the link (optional) • Show – new | replace | embed | undefined • Actuate – onLoad | onRequest | undefined
2002 Prentice Hall, Inc. All rights reserved. 16 Attributes of XLink • Show – how to display a resource when it is loaded new -- the resource displayed in a new window … replace – replacing the current resource embed – combining the current resource with the linked element other, none (undefined) – allowing XLink-aware application to decide how to display • Actuate – when the resource should be retrieved onLoad – document is retrieved as soon as it is loaded onRequest – doc. should not be retrieved until the user requests it other, none (undefined) – XLink-aware application to decide when to load
2002 Prentice Hall, Inc. All rights reserved. 17 2.2 Extended Links
• Extended links – Link multiple combinations of local and remote resources – Multidirectional links • Traverse between resources • Can link any number of resources • Unidirectional links may not offer return to local resource or the remote resource has no knowledge of the local resource • Require multiple elements to accomplish Extended links
2002 Prentice Hall, Inc. All rights reserved. 18 Two unidirectional links and Multidirectional links
document 1 document 2
document 1 document 2
document 1 document 2 document 3 document 4
2002 Prentice Hall, Inc. All rights reserved. 19 A Sample DTD of [extended] Element
2002 Prentice Hall, Inc. All rights reserved. 20 A Sample DTD of [resource] Element
2002 Prentice Hall, Inc. All rights reserved. 21 A Sample DTD of [title] Element
2002 Prentice Hall, Inc. All rights reserved. 22 A Sample DTD of [locator] Element
2002 Prentice Hall, Inc. All rights reserved. 23 A Sample DTD of [arc] Element
2002 Prentice Hall, Inc. All rights reserved. 24 1 Outline 2 3 4 Fig. 8 XML document 5 containing extended 6
2002 Prentice Hall, Inc. All rights reserved. 27 Fig. 9 XLink tree browser rendering of booklinks.xml
©Fujitsu Laboratories Ltd.
2002 Prentice Hall, Inc. All rights reserved. 28 Fig. 10 Traversing an outbound link.
©Fujitsu Laboratories Ltd.
2002 Prentice Hall, Inc. All rights reserved. 29 Fig. 11 Traversing an outbound link.
©Fujitsu Laboratories Ltd.
2002 Prentice Hall, Inc. All rights reserved. 30 Fig. 12 Ending resource shown in a new window.
©Fujitsu Laboratories Ltd.
2002 Prentice Hall, Inc. All rights reserved. 31 Types of Extended Links • locator – Specifies a remote resource • resource – Specifies a local resource • arc – Outbound arc using attributes from (local) and to (remote) – Inbound arc (starting resource remote and ending resource local) – Third-party arc (both starting and ending resources are remote)
2002 Prentice Hall, Inc. All rights reserved. 32 3 XLink and DTDs • DTDs are often used with documents that use XLink for: – Validation – Reduce the number of XLink attributes in XML document
2002 Prentice Hall, Inc. All rights reserved. 33 1 Outline 2 3 4 Defineextended element XLink 5 10 Line 7 11 Define element book 12 17 Lines 18-24 18 Define element 19 Define elementLine 28 publisher 25 and its attributes 26 27 Define element 33 warehouse andFig. its attributes13 DTD for 34 extended XLink 35 Define element 41 Lines arcElement42-50 and its attributes for specifying 42 traversal information 43 51 52 53 54 55 2002 Prentice Hall, Inc. All rights reserved. 35 4 XML Pointer Language (XPointer)
• XPointer – References fragments of XML document via a URI • Link to specific part of resource, instead of linking to entire resource • Link to specific locations (i.e., XPath tree nodes) • Link to ranges of locations – Uses XPath to reference XML document nodes – Also used for searching XML documents via string matching
2002 Prentice Hall, Inc. All rights reserved. 36 1 Outline 2 3 Fig. 14 Example 4 contact list. 5
2002 Prentice Hall, Inc. All rights reserved. 37 XPointer (cont.) • In Figure 14 – Assume contact list has relative URI /contacts.xml • XLink references entire contact list with URI xlink:href = "/contacts.xml" • XPointer references specific part: – Element contact with id of author02 xlink:href = "/contacts.xml#xpointer( //contact[@id = ‘author02]’)" • The name xpointer, called a scheme, expresses the full XPoint form. By using unique attribute id, the expression can be simplified by: xlink:href = "/contacts.xml#xpointer(id = ‘author02’)" which can be further simplified by xlink:href = "/contacts.xml#author02"
2002 Prentice Hall, Inc. All rights reserved. 38 XPointer is used in 4 MIME-Type:
• text/xml • application/xml • text/xml-external-parsed-entity • application/xml-external-parsed-entity
2002 Prentice Hall, Inc. All rights reserved. 39 XPointer and XLink • XLink and XPointer – XLink links to a designated XML document – XPointer links to internal node or range – XPointer can’t point to different XML document As an example xlink:type=“simple” xlink:href=“../chapter15/15-1.xml #xpointer(/purchaseOrder/customer/person[2])” xlink:title=…
Point to the second person element under customer
2002 Prentice Hall, Inc. All rights reserved. 40 XPointer and XPath • XPointer as an extension of XPath – Node location (節點) – Point location (點) – Range location (範圍) • Location set xpointer(/AAA/BBB[1]) xpointer(//BBB/DDD[2]) • string-range(loc,string,num1?,num2?) e.g. xpointer(string-range(//*,’element’,2,4) ) • start-point(location-set) e.g. xpointer(start-point(string-range(//*,’element’,1,1)[1]))
2002 Prentice Hall, Inc. All rights reserved. 41 Range and Point in XPointer • string-range() • start-point() • end-point() • range-to() • range() For example, 1. xpointer(start-point(string-range(//*.’element’,1,1)[1]) 2. xpointer(start-point(string-range(//*,’third’))) 3. xpoint(start-point(/)) 4. xpoint(start-point(//AAA)) Then, change “start” to “end”, point the location in the example XML file.
2002 Prentice Hall, Inc. All rights reserved. 42 Sample XML Document
2002 Prentice Hall, Inc. All rights reserved. 43 5 XML Inclusions (XInclude)
• XInclude – Reuse XML documents – Include XML documents within others – Use xinclude element
2002 Prentice Hall, Inc. All rights reserved. 44 6 XML Base (XBase) • XBase – Provide base URIs for relative links • Similar to HTML element base
• Uses attribute xml:base to provide the base URI http://deitel.net/ for attribute href. The complete URI reference by href is: http://deitel.net/authors/author01biography.xml
2002 Prentice Hall, Inc. All rights reserved.