290 likes | 720 Views
XLink, XPointer, XInclude and XBase. 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 XML Inclusions (XInclude) 6 XML Base (XBase). 1 Introduction. XLink
E N D
XLink, XPointer, XInclude and XBase Outline1 Introduction2 XML Linking Language (XLink) 2.1 Simple Links 2.2 Extended Links3 XLink and DTDs4 XML Pointer Language (XPointer)5 XML Inclusions (XInclude)6 XML Base (XBase)
1 Introduction • XLink • Describing links between resources (e.g., documents) • XPoint • “Pointing” to document contents • XInclude • Including existing XML document into another • XBase • Specifies “base” URL for relative URLs
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
2.1 Simple Links • Simple link • Links one resource to another (similarly to HTML link) • Linking elements • Specify linking information <book xlink:type ="simple" xlink:href ="/textbooks/xmlHowToProgram.xml"> • Linking element (book) is local resource • xmlHowToProgram.xml is remote resource • Arc • Markup that specifies how to traverse betweenresources
XLink Example <?xml version = "1.0"?> <contacts xmlns:xlink = "http://www.w3.org/1999/xlink"> <contact xlink:type = "simple" xlink:href = “brit.xml" xlink:role = "http://www.msn.com/brit" xlink:title = “Britney Spears"> xlink:show = "new“ xlink:actuate = "onRequest"> Britney </contact>
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
1 <?xml version ="1.0"?> 2 3 <!-- Fig. 14.8 : booklinks.xml --> 4 <!-- XML document containing extended links --> Mark up link to book’s authors 5 6 <books xmlns:xlink ="http://www.w3.org/1999/xlink" 7 xlink:type ="extended" 8 xlink:title ="Book Inventory"> Mark up link to publisher 9 10 <author xlink:label ="authorDeitel" Mark up link to warehouse 11 xlink:type ="locator" 12 xlink:href ="#authors" 13 xlink:role ="http://deitel.com/xlink/author" 14 xlink:title = "Deitel & 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" 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" 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"/> Fig. 14.8 XML document containing extended links. Lines 10-19Lines 21-25Lines 27-31
32 Create local resource JavaBook, which links to (or from) an author or publisher 33 <book xlink:label ="JavaBook" 34 xlink:type ="resource" Create outbound arc that links to arcrole when user requests it 35 xlink:role ="http://deitel.com/xlink/author" 36 xlink:title ="Textbook on Java"> 37 Java How to Program: Third edition Create outbound arc between book local resource and publisher local resource 38 </book> 39 40 <arcElement xlink:type ="arc" Create inbound arc that has starting remote reference (warehouseXYZ) and ending local resource (JavaBook) 41 xlink:from ="JavaBook" 42 xlink:arcrole ="http://deitel.com/xlink/info" 43 xlink:to ="authorDeitel" 44 xlink:show ="new" 45 xlink:actuate ="onRequest" 46 xlink:title ="About the author"/> 47 48 <arcElement xlink:type ="arc" 49 xlink:from ="JavaBook" 50 xlink:arcrole ="http://deitel.com/xlink/info" 51 xlink:to ="publisherPrenticeHall" 52 xlink:show ="new" 53 xlink:actuate ="onRequest" 54 xlink:title ="About the publisher"/> 55 56 <arcElement xlink:type ="arc" 57 xlink:from ="warehouseXYZ" 58 xlink:arcrole ="http://deitel.com/xlink/info" 59 xlink:to="JavaBook" 60 xlink:show="new" 61 xlink:actuate ="onRequest" 62 xlink:title ="Information about this book"/> 63 Fig. 14.8 XML document containing extended links (Part 2). Lines 33-38Lines 40-46Lines 48-54Lines 56-62
Extended Links Example <arcElement xlink:type = "arc" xlink:from = "JavaBook" xlink:arcrole = http://www.msn.com/xlink/jb xlink:to = "authorSpears“ xlink:show = "new“ xlink:actuate = "onRequest“ xlink:title = "About the author"/>
3 XLink and DTDs • DTDs used with documents that use XLink • Validation • Reduce the number of XLink attributes in XML document <car xmlns:xlink ="http://www.w3.org/1999/xlink"xlink:type ="simple"xlink:role ="MT4606"xlink:title ="The Latest Model"> • Provide default values in DTD, and rewrite as: <car xlink:role ="MT4606"xlink:title ="The Latest Model">
1 2 3 4 <!ELEMENT books (author, publisher, warehouse, book, persons, arcElemen t*)> 5 <!ATTLIST books 6 xmlns:xlink CDATA#FIXED "http://www.w3.org/1999/xlink" 7 xlink:type (extended) #FIXED "extended" 8 xlink:role CDATA#IMPLIED 9 xlink:title CDATA#IMPLIED> 10 11 <!ELEMENT book (#PCDATA)> 12 <!ATTLIST book 13 xlink:type (resource) #FIXED "resource" 14 xlink:role CDATA#FIXED "http://www.msn.com/xlink/book" 15 xlink:title CDATA#IMPLIED 16 xlink:label NMTOKEN#IMPLIED> 17 18 <!ELEMENT author (person*)> 19 <!ATTLIST author 20 xlink:type (locator) #FIXED "locator" 21 xlink:href CDATA#REQUIRED 22 xlink:role CDATA#FIXED "http://www.msn.com/xlink/author" 23 xlink:title CDATA#IMPLIED 24 xlink:label NMTOKEN#IMPLIED> 25 26 <!ELEMENT publisher EMPTY> 27 <!ATTLIST publisher 28 xlink:type (locator) #FIXED "locator" 29 xlink:href CDATA#REQUIRED 30 xlink:role CDATA#FIXED "http://www.msn.com/xlink/publisher"
31 xlink:title CDATA#IMPLIED 32 xlink:label NMTOKEN#IMPLIED> 33 34 <!ELEMENT warehouse EMPTY> 35 <!ATTLIST warehouse 36 xlink:type (locator) #FIXED "locator" 37 xlink:href CDATA#REQUIRED 38 xlink:role CDATA#FIXED "http://www.msn.com/xlink/warehouse" 39 xlink:title CDATA#IMPLIED 40 xlink:label NMTOKEN#IMPLIED> 41 42 <!ELEMENT arcElement EMPTY> 43 <!ATTLIST arcElement 44 xlink:type (arc) #FIXED "arc" 45 xlink:arcrole CDATA#IMPLIED 46 xlink:title CDATA#IMPLIED 47 xlink:from NMTOKEN#IMPLIED 48 xlink:to NMTOKEN#IMPLIED 49 xlink:show (new | replace | embed | undefined) #IMPLIED 50 xlink:actuate (onLoad | onRequest | undefined) #IMPLIED> 51 52 <!ELEMENT persons (person+)> 53 <!ATTLIST persons id ID #REQUIRED> 54 55 <!ELEMENT person (#PCDATA)>
4 XML Pointer Language (XPointer) • XPointer • References fragments of XML document via 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
1 <?xml version ="1.0"?> 2 <!-- contacts.xml --> 3 <!-- contact list document --> 4 5 <contacts> 6 <contact id ="author01">Spears, Britney</contact> 7 <contact id ="author02">Mubarak, Shakira</contact> 8 <contact id ="author03">JLo</contact> 9 </contacts> XPointer Example
4 XML Pointer Language • Example • 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]’)"
5 XML Inclusions (XInclude) • XInclude • Reuse XML documents • Include XML documents within others • Use include element <includerxmlns:xinclude ="http://www.w3.org/1999/XML/xinclude"xinclude:href ="test.xml"xinclude:parse ="xml"/>
6 XML Base (XBase) • XBase • Provide base URIs for relative links • Similar to HTML element base <contactxml:base ="http://www.msn.com"xlink:type ="simple"xlink:hrefs ="/authors/authors01biography.xml"xlink:role ="http://www.msn.com/xlink/contact"xlink:title ="About this author"/>