Sunteți pe pagina 1din 6

Introduction

 XLink (W3C Recommendation)


– Describing links between resources (e.g., documents)
Lecture 10  XPointer (W3C Recommendation)
– “Pointing” to document contents
 XInclude (W3C Recommendation)
XLink, XPointer, XInclude and XBase – Including existing XML document into another
 XBase (W3C Recommendation)
– Specifies “base” URL for relative URLs

2010.1 1 2010.1 2

XML Link Language (XLink) XLink

 XLink  Basic links and complex links


– Links to resources from XML documents  Allows XML documents to:
• files, images, documents, programs, and query results. – Assert linking relationships among more than two
– Combined with XPointer, can address a portion of a resources
resource, for example an element inside an XML – Associate metadata with a link
document. – Express links that reside in a location separate
from the linked resources
 To get access to XLink features the XLink
namespace must be declared:
– http://www.w3.org/1999/xlink

2010.1 3 2010.1 4

1
Simple Links XLink Attributes
 Attributes:
 Simple link
– type: specifies the type of linking. The value must be
– Links one resource to another (similarly to HTML link)
one of "simple", "extended", "locator", "arc",
– Linking elements "resource", "title", or "none".
• Specify linking information
<book xlink:type = "simple"
– href: defines the remote resource’s URI
xlink:href = "/textbooks/xmlHowToProgram.xml"> – role: references a resource that describes the link (a
XML Book </book> machine readable description of the link)
• Linking element (book) is local resource
– title: a descriptive title for the link (human readable)
• xmlHowToProgram.xml is remote resource
– show: specifies how to display a resource when it is
loaded
– actuate: specifies when the resource should be
d oc ume nt 1 do c ument 2 retrieved
2010.1 5 2010.1 6

1 <?xml version = "1.0"?>


2
3
4
<!-- Fig. 14.4 : simpleLinks2.xml
<!-- XML file that shows simple linking
-->
-->
XLink Attributes cont.
5
6 <contacts xmlns:xlink = "http://www.w3.org/1999/xlink">
7
8 <contact Create simple XLink link in element contact  Attribute show:
9 xlink:type = "simple" with about.xml as remote resource – new: indicates that the resource should be displayed in a new
10 xlink:href = "about.xml"
window or equivalent (depends on the application)
11 xlink:role = "http://www.deitel.com/xlink/contact"
Attribute show specifies – replace: replaces the current resource with the linked resource
12 xlink:title = "About Harvey Deitel"
how to display resources
13 xlink:show = "new" – embed: replaces the current element with the linked resource
14 xlink:actuate = "onRequest">
15 Attribute actuate – other or none allows the application to decide how to display the
16 Dr. Harvey Deitel specifies when resources link
17 </contact> show be retrieved
18  Attribute actuate:
19 </contacts>
– onRequest: resource should not be retrieved until the user
requests it
– onLoad: the document should be retrieved as soon as it is
loaded
– other: application decides when to load the resource

2010.1 7 2010.1 8

2
Extended Links Unidirectional vs Multidirectional links

 Extended links
– Link multiple combinations of local and remote
resources
– Can create multidirectional links for traversing d oc ument 1 do c ument 2
between resources.
– Not limited to just two resources, can link any number
of resources.
• Unidirectional links may not offer return to local resource
• Multidirectional links
– Traverse between resources d oc ument 1 do c ument 2

2010.1 9 2010.1 10

Multidirectional linking between


four resources.

do c ument 1 doc um ent 2 doc um ent 3 d oc um ent 4

2010.1 11 2010.1 12

3
1 <?xml version = "1.0"?>
2
3 <!-- Fig. 14.8 : booklinks.xml -->
4 <!-- XML document containing extended links -->
5
6 <books xmlns:xlink = "http://www.w3.org/1999/xlink"
7 xlink:type = "extended"
– Arc 8
9
xlink:title = "Book Inventory">

• Markup that specifies how to traverse between resources, 10 <author xlink:label = "authorDeitel" Mark up link to book’s authors
11 xlink:type = "locator"
including the direction of traversal. 12 xlink:href = "#authors"
13 xlink:role = "http://deitel.com/xlink/author"
14 xlink:title = "Deitel &amp; Associates, Inc.">
15 <persons id = "authors">
16 <person>Deitel, Harvey</person>
17 <person>Deitel, Paul</person>
18 </persons>
19 </author>
20
21 <publisher xlink:label = "publisherPrenticeHall" Mark up link to publisher
22 xlink:type = "locator"
23 xlink:href = "/publisher/prenticehall.xml"
24 xlink:role = "http://deitel.com/xlink/publisher"
25 xlink:title = "Prentice Hall"/>
26
27 <warehouse xlink:label = "warehouseXYZ" Mark up link to warehouse
28 xlink:type = "locator"
29 xlink:href = "/warehouse/xyz.xml"
30 xlink:role = "http://deitel.com/xlink/warehouse"
31 xlink:title = "X.Y.Z. Books"/>
2010.1 13 2010.1 14

32 Create local resource 64 <arcElement xlink:type = "arc"


33 <book xlink:label = "JavaBook" JavaBook, which links to (or 65 xlink:from = "publisherPrenticeHall"
34 xlink:type = "resource"
from) an author or publisher 66 xlink:arcrole = "http://deitel.com/xlink/stock"
35 xlink:role = "http://deitel.com/xlink/author"
67 xlink:to = "warehouseXYZ"
36 xlink:title = "Textbook on Java">
68 xlink:show = "embed"
37 Java How to Program: Third edition
38 </book> 69 xlink:actuate = "onLoad"
39 70 xlink:title = "Publisher&apos;s inventory"/>
40 <arcElement xlink:type = "arc"
Create outbound arc that links to 71
Create third-party arc that has both
41 xlink:from = "JavaBook" arcrole when user requests it 72 </books> starting and ending remote references
42 xlink:arcrole = "http://deitel.com/xlink/info" (publisherPrenticeHall and
43 xlink:to = "authorDeitel" warehouseXYZ)
44 xlink:show = "new"
45 xlink:actuate = "onRequest"
46 xlink:title = "About the author"/>
47
48 <arcElement xlink:type = "arc"
Create outbound arc between book local
49 xlink:from = "JavaBook" resource and publisher local resource
50 xlink:arcrole = "http://deitel.com/xlink/info"
51 xlink:to = "publisherPrenticeHall"
52 xlink:show = "new"
53 xlink:actuate = "onRequest" Arc:
54 xlink:title = "About the publisher"/>
55 Create inbound arc that has starting Markup that specifies how to traverse between resources, including the direction of traversal.
56 <arcElement xlink:type = "arc" remote reference (warehouseXYZ) and
57 xlink:from = "warehouseXYZ"
58 xlink:arcrole = "http://deitel.com/xlink/info"
ending local resource (JavaBook)
59 xlink:to = "JavaBook"
60 xlink:show = "new"
61 xlink:actuate = "onRequest"
62 xlink:title = "Information about this book"/>
63
2010.1 15 2010.1 16

4
1 <?xml version = "1.0"?>
2 <!-- Fig. 14.14 : contacts.xml -->
XML Pointer Language (XPointer) 3 <!-- contact list document -->
4
5 <contacts>
6 <contact id = "author01">Deitel, Harvey</contact>
Mark up contact list that
 XPointer 7 <contact id = "author02">Deitel, Paul</contact>
contains ids for three authors
8 <contact id = "author03">Nieto, Tem</contact>
– References fragments of XML document via URI 9 </contacts>

• 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

2010.1 17 2010.1 18

XML Pointer Language (cont.) XML Inclusions (XInclude)

 For previous slide  XInclude


– Assume contact list has relative URI /contacts.xml – Reuse XML documents
• XLink references entire contact list with URI – Include XML documents within others
xlink:href = "/contacts.xml"
– Use include element
• XPointer references specific part:
<includer
xmlns:xinclude = "http://www.w3.org/1999/XML/xinclude"
xlink:href = "/contacts.xml#xpointer(//contact[@id = ‘author02’])" xinclude:href = "test.xml"
xinclude:parse = "xml"/>
References element contact with id of author02 in document contacts.xml

2010.1 19 2010.1 20

5
XML Base (XBase) More Information

 XBase  W3C XLink Recommendation


– Provide base URIs for relative links http://www.w3.org/TR/2001/REC-xlink-20010627/
• Similar to HTML element base  W3C XML Base Recommendation
<contact
xml:base = "http://deitel.net" http://www.w3.org/TR/xmlbase/
xlink:type = "simple"
xlink:hrefs = "/authors/authors01biography.xml"  W3C XML Pointer, -Base, and -Linking
xlink:role = "http://deitel.com/xlink/contact"
xlink:title = "About this author"/>
http://www.w3.org/XML/Linking
 W3C XML Inclusions (XInclude)
Recommendation
http://www.w3.org/TR/xinclude/

2010.1 21 2010.1 22

 Reference:
 Deitel, H., P.Deitel, T. Nieto, T.Lin and P. Sadlu.
(2001). XML: How to Program 1e. Upper Saddle
River: Pearson Education
 W3C – www.w3.org

2010.1 23

S-ar putea să vă placă și