XQuery – Part IV

XML Foundations [./]
Fall 2011 — INFO 242 (CCN 42596)

Erik Wilde, UC Berkeley School of Information
2011-10-13

Creative Commons License [http://creativecommons.org/licenses/by/3.0/]

This work is licensed under a CC
Attribution 3.0 Unported License
[http://creativecommons.org/licenses/by/3.0/]

Contents E. Wilde: XQuery – Part IV

Contents

E. Wilde: XQuery – Part IV

(2) Abstract

This last part of the XQuery lectures covers some additional XQuery topics and briefly looks into how to create user-defined functions. After that, XML linking methods are considered, specifically xml:id, XML Inclusions (XInclude), and the XML Linking Language (XLink). These methods are used as a starting point to look at potential XML processing in XQuery, specifically, how to use XQuery code to identify and dereference the links that are used in the XInclude vocabulary.



More XQuery Details

Outline (More XQuery Details)

  1. More XQuery Details [3]
  2. User-Defined Functions [2]
  3. Linking in XML [11]
    1. XML IDs with xml:id [1]
    2. XML Inclusions (XInclude) [2]
    3. XML Linking Language (XLink) [6]
      1. Simple Links [1]
      2. Extended Links [5]
    4. Linking Conclusions [1]
More XQuery Details E. Wilde: XQuery – Part IV

(4) Comma Operator



More XQuery Details E. Wilde: XQuery – Part IV

(5) Whitespace in XQuery

declare boundary-space strip;
let $a := "Bob Glushko"
return
  <book>
	<title>Document Engineering</title>
	<author> { $a } </author>
  </book>


More XQuery Details E. Wilde: XQuery – Part IV

(6) Constructors



User-Defined Functions

Outline (User-Defined Functions)

  1. More XQuery Details [3]
  2. User-Defined Functions [2]
  3. Linking in XML [11]
    1. XML IDs with xml:id [1]
    2. XML Inclusions (XInclude) [2]
    3. XML Linking Language (XLink) [6]
      1. Simple Links [1]
      2. Extended Links [5]
    4. Linking Conclusions [1]
User-Defined Functions E. Wilde: XQuery – Part IV

(8) Reusable code in XQuery

declare function local:onetwothree() as xs:integer+ { (1, 2, 3) };


User-Defined Functions E. Wilde: XQuery – Part IV

(9) Local Function

declare function local:format-date($date) { string($date) } ;

<html>
 <body>
  <table border="1" cellpadding="20">
   { for $post in //post return
    <tr>
     <td><a href="../img/{ $post/image/@src }.jpg"><img src="../img/{ $post/image/@src }-small.jpg"/></a></td>
     <td>
      <h2> { local:format-date($post/@date) }: { $post/title/text() } </h2>
      <p> { $post/text/text() } </p>
     </td>
    </tr>
   }
  </table>
 </body>
</html>


Linking in XML

Outline (Linking in XML)

  1. More XQuery Details [3]
  2. User-Defined Functions [2]
  3. Linking in XML [11]
    1. XML IDs with xml:id [1]
    2. XML Inclusions (XInclude) [2]
    3. XML Linking Language (XLink) [6]
      1. Simple Links [1]
      2. Extended Links [5]
    4. Linking Conclusions [1]
Linking in XML E. Wilde: XQuery – Part IV

(11) Links in XML



XML IDs with xml:id

XML IDs with xml:id E. Wilde: XQuery – Part IV

(13) References in Instances

  • DTD [Document Type Definition (DTD)] and XSD [XSD – Part I] IDs are defined in the schema
    • the important information is the (attribute) type in the schema
    • the name of the attribute can be freely chosen by the schema designer
  • xml:id [http://www.w3.org/TR/xml-id/] establishes a well-know attribute name for IDs
    • the IDness of an attribute is established by its name
    • IDs can be found without any schema (there does not even has to be one)
  • xml:id uses XML's own namespace to identify identifiers
<section id="introduction">
<section xml:id="introduction">


XML Inclusions (XInclude)

XML Inclusions (XInclude) E. Wilde: XQuery – Part IV

(15) Including Trees into Trees

  • XInclude [http://www.w3.org/TR/xinclude/] defines an inclusion facility for XML
    • it is a separate standard and not part of XML itself
    • XML processors might or might not support XInclude
  • XInclude is defined as replacing XInclude elements with included content
    • logically speaking, XInclude is thus defined as a tree transformation
    • practically speaking, it can thus be implemented in XSLT [http://dret.net/projects/xipr/]
<x xmlns:xi="http://www.w3.org/2001/XInclude">
	<xi:include href="something.xml"/>
	<xi:include xpointer="xmlns(xi=http://www.w3.org/2001/XInclude)xpointer(x/xi:include[1])" parse="xml"/>
</x>


XML Inclusions (XInclude) E. Wilde: XQuery – Part IV

(16) XInclude Schema

<!ELEMENT xi:include (xi:fallback?)>
<!ATTLIST xi:include
	xmlns:xi		CDATA	   #FIXED	"http://www.w3.org/2001/XInclude"
	href			CDATA	   #IMPLIED
	parse		   (xml|text)  "xml"
	xpointer		CDATA	   #IMPLIED
	encoding		CDATA	   #IMPLIED
	accept		  CDATA	   #IMPLIED
	accept-language CDATA	   #IMPLIED
>


Linking Conclusions

Linking Conclusions E. Wilde: XQuery – Part IV

(27) Linking XML

  • XML documents often are part of a bigger picture
  • Linking documents is not readily covered by XML specs
  • Different approaches have different side-effects
  • First consider the objectives before choosing a solution


2011-10-13 XML Foundations [./]
Fall 2011 — INFO 242 (CCN 42596)