<<

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 • 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 – Simple links or extended links – HTML, HyTime, and (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 ), 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 Lines 18-25 7 8 Deitel & Associates, Inc. is an internationally recognized 9 corporate training and content creation organization specializing 10 in programming languages, / technology and 11 object technology education. Deitel & Associates, Inc. is a 12 member of the World Wide Web Consortium. The company provides 13 elementary through advanced courses on Java, C++, Visual Basic, 14 C, Perl, Python, XML, Internet and World Wide Web programming, 15 e-business and e-commerce programming and Object Technology. 16 The principals of Deitel & Associates, Inc. are 17 Create simple XLink link in element contact 18 23 24 Dr. Harvey Deitel 25 26  2002 Prentice Hall, Inc. All rights reserved. 8 27 and Paul J. Deitel. The company's clients include many of Outline 28 the world's largest computer companies, government agencies, 29 branches of the military and business organizations. Through its Fig.2 XML document 30 publishing partnership with Prentice Hall, Deitel & Associates, with a simple link (Part 31 Inc. publishes leading-edge programming textbooks, professional 2). 32 books, interactive CD-ROM-based multimedia Cyber Classrooms, 33 satellite courses and Web-based training courses. 34

 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 7 Dr. Harvey M. Deitel, CEO of Deitel & Associates, Inc., has 8 40 years experience in the computing field including extensive 9 industry and academic experience. He is one of the world's 10 leading computer science instructors and seminar presenters. 11 Dr. Deitel earned B.S. and M.S. degrees from the Massachusetts 12 Institute of Technology and a Ph.D. from Boston University. 13 He worked on the pioneering virtual memory operating systems 14 projects at IBM and MIT that developed techniques widely 15 implemented today in systems like UNIX, Linux and Windows NT. 16 He has 20 years of college teaching experience including earning 17 tenure and serving as the Chairman of the Computer Science 18 Department at Boston College before founding Deitel & 19 Associates, Inc. with Paul J. Deitel. He is author or co-author 20 of several dozen books and multimedia packages and is currently 21 writing many more. With translations published in Japanese, 22 Russian, Spanish, Elementary Chinese, Advanced Chinese, Korean, 23 French, Polish, Portuguese and Italian, Dr. Deitel's texts have 24 earned international recognition. Dr. Deitel has delivered 25 professional seminars internationally to major corporations, 26 government organizations and various branches of the military. 27  2002 Prentice Hall, Inc. All rights reserved. 12 1 Outline 2 3 Fig. 4 Attributes show 4 and . 5 actuate 6 7 Create simple XLink linkLines in element 8-17 8 Attribute 15 actuate specifies when resources 16 Dr. Harvey Deitel should be retrieved 17 18 19

 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 9 Lines 10-19 10 15 16 Deitel, Harvey 17 Deitel, Paul 18 19 20 21 26 27  2002 Prentice Hall, Inc. All rights reserved. 25 32 Create local resourceOutline 33 containing extended 37 Java How to Program: Third edition links (Part 2). 38 39 Create outbound arc that links to Lines 33-38 40 47 Create outboundLines arc between 56-62 book local 48 55 Create inbound arc that has starting 56 63  2002 Prentice Hall, Inc. All rights reserved. 26 64 Create third-party arc that has both Lines 64-70 71 starting and ending remote references 72 (publisherPrenticeHall and warehouseXYZ)

 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 – Provide default values in DTD, and rewrite as:

 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 6 Deitel, Harvey Lines 5-9 Mark up contact list that 7 Deitel, Paul contains ids for three authors 8 Nieto, Tem 9

 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#( //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 first element BBB. second element BBB. element CCC.

 2002 Prentice Hall, Inc. All rights reserved. 43 5 XML Inclusions (XInclude)

• XInclude – Reuse XML documents – Include XML documents within others – Use 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.