XML Model and Processing Transparency No. 1 Query XML Documents with XQuery Cheng-Chia Chen.

Slides:



Advertisements
Similar presentations
XML Data Management 8. XQuery Werner Nutt. Requirements for an XML Query Language David Maier, W3C XML Query Requirements: Closedness: output must be.
Advertisements

XML: Extensible Markup Language
CSE 6331 © Leonidas Fegaras XML and Relational Databases 1 XML and Relational Databases Leonidas Fegaras.
XQuery John Annechino Steven Pow. Agenda What is XQuery? Uses of XQuery XQuery vs. XSLT Syntax –Built-In Functions –FLWOR –if-then-else –User-Defined.
Paper by: A. Balmin, T. Eliaz, J. Hornibrook, L. Lim, G. M. Lohman, D. Simmen, M. Wang, C. Zhang Slides and Presentation By: Justin Weaver.
Friday, September 4 th, 2009 The Systems Group at ETH Zurich XML and Databases Exercise Session 6 courtesy of Ghislain Fourny/ETH © Department of Computer.
Static Typing in XQuery Mary Fernández, Jérôme Siméon, Philip Wadler Επιμέλεια Παρουσίασης: Μαγδαληνός Παναγής.
Introduction to XLink Transparency No. 1 XML Information Set W3C Recommendation 24 October 2001 (1stEdition) 4 February 2004 (2ndEdition) Cheng-Chia Chen.
1 COS 425: Database and Information Management Systems XML and information exchange.
XML –Query Languages, Extracting from Relational Databases ADVANCED DATABASES Khawaja Mohiuddin Assistant Professor Department of Computer Sciences Bahria.
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
Introduction to XML This material is based heavily on the tutorial by the same name at
1 Advanced Topics XML and Databases. 2 XML u Overview u Structure of XML Data –XML Document Type Definition DTD –Namespaces –XML Schema u Query and Transformation.
Processing of structured documents Spring 2003, Part 8 Helena Ahonen-Myka.
Introduction to XPath Bun Yue Professor, CS/CIS UHCL.
SD2520 Databases using XML and JQuery
XMLII XSchema XSchema XQuery XQuery. XML Schema XML Schema is a more sophisticated schema language which addresses the drawbacks of DTDs. Supports XML.
4/20/2017.
XML, distributed databases, and OLAP/warehousing The semantic web and a lot more.
XP New Perspectives on XML Tutorial 4 1 XML Schema Tutorial – Carey ISBN Working with Namespaces and Schemas.
Sheet 1XML Technology in E-Commerce 2001Lecture 6 XML Technology in E-Commerce Lecture 6 XPointer, XSLT.
Lecture 21 XML querying. 2 XSL (eXtensible Stylesheet Language) In HTML, default styling is built into browsers as tag set for HTML is predefined and.
Lecture 6 of Advanced Databases XML Schema, Querying & Transformation Instructor: Mr.Ahmed Al Astal.
TDDD43 XML and RDF Slides based on slides by Lena Strömbäck and Fang Wei-Kleiner 1.
Comparing XSLT and XQuery Michael Kay XTech 2005.
Lecture 6 of Advanced Databases XML Querying & Transformation Instructor: Mr.Eyad Almassri.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation An Introduction to XQuery.
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
WORKING WITH XSLT AND XPATH
1 Querying XML Documents. 2 Objectives How XML generalizes relational databases The XQuery language How XML may be supported in databases.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation An Introduction to XQuery.
Sofia, Bulgaria | 9-10 October Using XQuery to Query and Manipulate XML Data Stephen Forte CTO, Corzen Inc Microsoft Regional Director NY/NJ (USA) Stephen.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
What is XML?  XML stands for EXtensible Markup Language  XML is a markup language much like HTML  XML was designed to carry data, not to display data.
The main mathematical concepts that are used in this research are presented in this section. Definition 1: XML tree is composed of many subtrees of different.
Company LOGO OODB and XML Database Management Systems – Fall 2012 Matthew Moccaro.
 XML is designed to describe data and to focus on what data is. HTML is designed to display data and to focus on how data looks.  XML is created to structure,
Chapter 27 The World Wide Web and XML. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.27-2 Topics in this Chapter The Web and the Internet.
Processing of structured documents Spring 2002, Part 2 Helena Ahonen-Myka.
Lecture 22 XML querying. 2 Example 31.5 – XQuery FLWOR Expressions ‘=’ operator is a general comparison operator. XQuery also defines value comparison.
Introduction to XQuery Bun Yue Professor, CS/CIS UHCL.
ECA 228 Internet/Intranet Design I XSLT Example. ECA 228 Internet/Intranet Design I 2 CSS Limitations cannot modify content cannot insert additional text.
CITA 330 Section 6 XSLT. Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "
XSLT part of XSL (Extensible Stylesheet Language) –includes also XPath and XSL Formatting Objects used to transform an XML document into: –another XML.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation Query Data Model Lecturer.
Database Systems Part VII: XML Querying Software School of Hunan University
Declaratively Producing Data Mash-ups Sudarshan Murthy 1, David Maier 2 1 Applied Research, Wipro Technologies 2 Department of Computer Science, Portland.
XML query. introduction An XML document can represent almost anything, and users of an XML query language expect it to perform useful queries on whatever.
XML and Database.
XMLTA Transparency No. 1 Query XML Documents with XQuery Cheng-Chia Chen.
QUALITY CONTROL WITH SCHEMAS CSC1310 Fall BASIS CONCEPTS SchemaSchema is a pass-or-fail test for document Schema is a minimum set of requirements.
XSD: XML Schema Language Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
XML Query: xQuery Reference: Xquery By Priscilla Walmsley, Published by O’Reilly.
XP New Perspectives on XML, 2 nd Edition Tutorial 7 1 TUTORIAL 7 CREATING A COMPUTATIONAL STYLESHEET.
Session II Chapter 3 – Chapter 3 – XPath Patterns & Expressions Chapter 4 – XPath Functions Chapter 15 – XPath 2.0http://
Session 1 Module 1: Introduction to Data Integrity
Friday, September 4 th, 2009 The Systems Group at ETH Zurich XML and Databases Exercise Session 5 courtesy of Ghislain Fourny/ETH © Department of Computer.
XPath --XML Path Language Motivation of XPath Data Model and Data Types Node Types Location Steps Functions XPath 2.0 Additional Functionality and its.
Module 3: Using XML. Overview Retrieving XML by Using FOR XML Shredding XML by Using OPENXML Introducing XQuery Using the xml Data Type.
Lecture 23 XQuery 1.0 and XPath 2.0 Data Model. 2 Example 31.7 – User-Defined Function Function to return staff at a given branch. DEFINE FUNCTION staffAtBranch($bNo)
1 The XPath Language. 2 XPath Expressions Flexible notation for navigating around trees A basic technology that is widely used uniqueness and scope in.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
Rendering XML Documents ©NIITeXtensible Markup Language/Lesson 5/Slide 1 of 46 Objectives In this session, you will learn to: * Define rendering * Identify.
XML: Extensible Markup Language
Unit 4 Representing Web Data: XML
Querying and Transforming XML Data
{ XML Technologies } BY: DR. M’HAMED MATAOUI
Chapter 7 Representing Web Data: XML
More XML XML schema, XPATH, XSLT
Presentation transcript:

XML Model and Processing Transparency No. 1 Query XML Documents with XQuery Cheng-Chia Chen

Introduction to XLink Transparency No. 2 Objectives How XML generalizes relational databases The XQuery language How XML may be supported in databases

Introduction to XLink Transparency No. 3 XQuery 1.0 XML documents naturally generalize database relations XQuery is the corresponding generalization of SQL

Introduction to XLink Transparency No. 4 Queries on XML documents XML documents generalize relational data: relations (tables) tuples (record; rows) attributes (fields; columns)

Introduction to XLink Transparency No. 5 From Relations to Trees

Introduction to XLink Transparency No. 6 Only Some Trees are Relations A relation is a tree of height two with an unbounded number of children (rows) all of which have the same fixed number of child nodes (columns) The database community has been looking for a richer data model than relations. Hierarchical, object-oriented, or multi-dimensional databases have emerged, but neither has reached consensus. A DTD for RDB :

Introduction to XLink Transparency No. 7 Trees Are Not Relations Not all XML Document trees satisfy the previous characterization Trees are ordered, while both rows and columns of tables may be permuted without changing the meaning of the data Trees may have height > 2. Trees is in general not homogeneous.  Elements of the same type may have different number and types of children. This does not mean that we cannot store these documents in traditional data base but only that a more complex encoding of xml documents into data base tables is necessary.

Introduction to XLink Transparency No. 8 An examlpe student grade records Joe Average 21 Biology Jack Doe 18 Physics XML Science

Introduction to XLink Transparency No. 9 A Corresponding Student Database key point of data base design: decompose general xml tree into flat data base tables

Introduction to XLink Transparency No. 10 For Relational Data base, we have well-established theory and practice, can we have the same achievement for XML ? database XML DDL(DataDefintionLang) XML Schema DQL(DataQueryLang;SQL) XQuery How should query languages like SQL be similarly generalized?

Introduction to XLink Transparency No. 11 Usage Scenarios of an XML query language For data-oriented (highly structured) languages We want to carry over the kinds of queries that we performed in the original relational model query (virtual) XML representations of databases, transform data into new XML representations, integrate data from multiple heterogeneous data sources For document-oriented (semi-structured) languages Queries could be used to retrieve parts of documents to provide dynamic indexes to perform context-sensitive searching to generate new documents as combinations of existing documents Studied in the domain of informational retrieval (IR)

Introduction to XLink Transparency No. 12 Usage Scenarios For programming/protocol languages Queries could be used to automatically generate documentation, like javadoc. For hybrid languages Queries could be used to data mine hybrid data, such as patient records to perform queries on documents with embedded data, such as catalogs, patient health records, employment records, or business analysis documents

Introduction to XLink Transparency No. 13 XQuery Design Requirements Must have at least one XML syntax and at least one human-readable syntax Must be declarative Must be namespace aware Must coordinate with XML Schema Must support simple and complex datatypes Must combine information from multiple documents Must be able to transform and create XML trees

Introduction to XLink Transparency No. 14 The XQuery language Developed by W3C, currently at the level of a Working Draft.currently Derived from several previous proposals: XML-QL YATL Lorel Quilt which all agree on the fundamental principles. XQuery relies on XPath and XML Schema datatypes. Although not finalized yet, many commercial implementations have been released.commercial implementations Two formats XQuery : plaintext syntax XQueryX : XML syntax.

Introduction to XLink Transparency No. 15 Relationship to XPath XQuery 1.0 is a strict superset of XPath 2.0 Every XPath 2.0 expression is directly an XQuery 1.0 expression (a query) The extra expressive power is the ability to join information from different sources and generate new XML fragments

Introduction to XLink Transparency No. 16 Relationship to XSLT XQuery and XSLT are both domain-specific languages for combining and transforming XML data from multiple sources They are vastly different in design, partly for historical reasons XQuery is designed from scratch, XSLT is an intellectual descendant of CSS (cascaded StyleSheet) – about how to render a document. Technically, they may emulate each other. XQuery Grammar

Introduction to XLink Transparency No. 17 XQuery concepts A query in XQuery is an expression that: reads a sequence of XML fragments or atomic values returns a sequence of XML fragments or atomic values The principal forms of XQuery expressions are: path expressions element constructors FLWR ("flower") expressions list expressions conditional expressions quantified expressions datatype expressions

Introduction to XLink Transparency No. 18 XQuery Modules and Prologs An XQuery is: a main module + zero or more library modules. MainModule ::= Prolog QueryBobyMainModule LibraryModule ::= ModuleDecl PrologLibraryModule Module ::= VersionDecl? (MainModule | LibraryModule)VersionDecl Like XPath expressions, XQuery expressions are evaluated relatively to a context This is explicitly provided by a prolog Settings define various parameters for the XQuery processor language, such as: xquery version "1.0"; (: this is verisondecl :) declare xmlspace preserve; declare xmlspace strip;

Introduction to XLink Transparency No. 19 More From the Prolog PrologProlog ::= ( (DefaultNamespaceDecl | Setter | NamespaceDecl | Import)DefaultNamespaceDeclSetterNamespaceDeclImport Separator )*Separator ( (VarDecl | FunctionDecl | OptionDecl)VarDeclFunctionDeclOptionDecl Separator )*Separator [21] SchemaImport ::= "import" "schema" SchemaPrefix? URILiteral ("at" URILiteral ("," URILiteral)*)?SchemaImportSchemaPrefixURILiteral [22] SchemaPrefix ::= ("namespace" NCName "=") | ("default" "element" "namespace")SchemaPrefixNCName [23] ModuleImport ::= "import" "module" ("namespace" NCName "=")? URILiteral ("at" URILiteral ("," URILiteral)*)?ModuleImportNCNameURILiteral (: for element and type :) declare default element namespace URI; declare default function namespace URI; import schema namespace soap=" at " declare namespace NCName = URI;

Introduction to XLink Transparency No. 20 Implicit Declarations declare namespace xml = " (: for xml schema and schema instance :) xs = " xsi = " (: for xpath fucntion and data types :) fn = " (: for xquery fucntions :) local=" only xml prefix cannot be redefined.

Introduction to XLink Transparency No. 21 Xquery Conecpts QueryBody = Expr [31] Expr ::= ExprSingle ("," ExprSingle)*ExprExprSingle [32] ExprSingle ::= FLWORExpr | QuantifiedExpr | TypeswitchExpr | IfExpr | OrExprExprSingleFLWORExprQuantifiedExprTypeswitchExprIfExprOrExpr Expressions are evaluated relative to a context: namespaces variables functions date and time context item (current node or atomic value) context position (in the sequence being processed) context size (of the sequence being processed)

Introduction to XLink Transparency No. 22 XPath Expressions XPath expressions are also legal XQuery expressions same data model : sequence of items items : nodes or atomic data The XQuery prolog gives the required static context namespace, function library, variable bindings The initial context node, position, and size are undefined Since XQuery is intended to operate on multple docuemnts. initial context info can be obtained by starting from fn:doc()

Introduction to XLink Transparency No. 23 Datatype Expressions Same atomic values as XPath 2.0 Also lots of primitive simple values: xs:string("XML is fun") xs:boolean("true") xs:decimal("3.1415") xs:float(" E23") xs:dateTime(" T13:20:00-05:00") xs:time("13:20:00-05:00") xs:date(" ") xs:gYearMonth(" ") xs:gYear("1999") xs:hexBinary("48656c6c6f0a") xs:base64Binary("SGVsbG8K") xs:anyURI(" xs:QName("rcp:recipe") Functions for theses types can be found in fn:XXX().

Introduction to XLink Transparency No. 24 XML Expressions XQuery expressions may compute new XML nodes Expressions may denote element, character data, comment, and processing instruction nodes Each node is created with a unique node identity Constructors may be either direct (literal template ) or computed

Introduction to XLink Transparency No. 25 Uses the standard XML syntax Ex: The expression baz evaluates to the given XML fragment Note that is evaluates to false why ? ( unique identity of each node ) Direct Constructors

Introduction to XLink Transparency No. 26 Namespaces in Constructors (1/3) The following three constructions have the same effect. declare default element namespace " John Doe CEO, Widget Inc. (202)

Introduction to XLink Transparency No. 27 Namespaces in Constructors (2/3) declare namespace b = " John Doe CEO, Widget Inc. (202)

Introduction to XLink Transparency No. 28 Namespaces in Constructors (3/3) John Doe CEO, Widget Inc. (202)

Introduction to XLink Transparency No. 29 Enclosed Expressions Called attribuate value template in XSLT can be appled to element contents also {1, 2, 3, 4, 5} {1, "2", 3, 4, 5} {1 to 5} 1 {1+1} {" "} {"3"} {" "} {4 to 5} ‘ { ‘ now has special meaning and must be escaped using {

Introduction to XLink Transparency No. 30 Explicit Constructors John Doe CEO, Widget Inc. (202) element card { namespace { " }, element name { text { "John Doe" } }, element title { text { "CEO, Widget Inc." } }, element { text { } }, element phone { text { "(202) " } }, element logo { attribute uri { "widget.gif" } }}

Introduction to XLink Transparency No. 31 Computed QNames element { "card" } { namespace { " }, element { "name" } { text { "John Doe" } }, element { "title" } { text { "CEO, Widget Inc." } }, element { " " } { text { } }, element { "phone" } { text { "(202) " } }, element { "logo" } { attribute { "uri" } { "widget.gif" } }

Introduction to XLink Transparency No. 32 element { if ($lang= ” zh_TW “ ) then ” 名片 " else "card" } { namespace { " }, element { if ($lang= “ zh_TW ” ) then ” 姓名 " else "name" } { text { "John Doe" } }, element { if ($lang= ” zh_TW “ ) then ” 頭銜 " else "title" } { text { "CEO, Widget Inc." } }, element { " " } { text { } }, element { if ($lang= “ zh_TW ” ) then ” 電話 " else "phone"} { text { "(202) " } }, element { "logo" } { attribute { "uri" } { "widget.gif" } }} Biliingual Business Cards

Introduction to XLink Transparency No. 33 FLWOR Expressions Used for general queries: Find the names of all students which have more than one major and order them by student id. { for $s in fn:doc("students.xml")//student let $m := $s/major where fn:count($m) ge 2 order by return { $s/name/text() } }

Introduction to XLink Transparency No. 34 The Difference Between For and Let (1/4) for $x in (1, 2, 3, 4) let $y := ("a", "b", "c") return ($x, $y) 1, a, b, c, 2, a, b, c, 3, a, b, c, 4, a, b, c

Introduction to XLink Transparency No. 35 The Difference Between For and Let (2/4) let $x in (1, 2, 3, 4) for $y := ("a", "b", "c") return ($x, $y) 1, 2, 3, 4, a, 1, 2, 3, 4, b, 1, 2, 3, 4, c

Introduction to XLink Transparency No. 36 The Difference Between For and Let (3/4) for $x in (1, 2, 3, 4) for $y in ("a", "b", "c") return ($x, $y) 1, a, 1, b, 1, c, 2, a, 2, b, 2, c, 3, a, 3, b, 3, c, 4, a, 4, b, 4, c

Introduction to XLink Transparency No. 37 The Difference Between For and Let (4/4) let $x := (1, 2, 3, 4) let $y := ("a", "b", "c") return ($x, $y) 1, 2, 3, 4, a, b, c

Introduction to XLink Transparency No. 38 Computing Joins Find distinct names of recipses that make use of at least one stuff in a refrigerator? declare namespace rcp = " for $r in fn:doc("recipes.xml")//rcp:recipe for $i in for $s in fn:doc("fridge.xml")//stuff[text()=$i] return fn:distinct($r/rcp:title/text()) eggs olive oil ketchup unrecognizable moldy thing

Introduction to XLink Transparency No. 39 Inverting a Relation From Recipe  ingredients to ingredietn  recipes declare namespace rcp = " { for $i in distinct-values( ) return { for $r in fn:doc("recipes.xml")//rcp:recipe where return $r/rcp:title/text() } }

Introduction to XLink Transparency No. 40 Sorting the Results declare namespace rcp = " { for $i in distinct-values( ) order by $i return { for $r in fn:doc("recipes.xml")//rcp:recipe where order by $r/rcp:title/text() return $r/rcp:title/text() } }

Introduction to XLink Transparency No. 41 A More Complicated Sorting for $s in document("students.xml")//student order by descending, fn:count($s/major) descending, xs:integer($s/age/text()) ascending return $s/name/text()

Introduction to XLink Transparency No. 42 Using Functions declare function local:grade($g) { if ($g="A") then 4.0 else if ($g="A-") then 3.7 else if ($g="B+") then 3.3 else if ($g="B") then 3.0 else if ($g="B-") then 2.7 else if ($g="C+") then 2.3 else if ($g="C") then 2.0 else if ($g="C-") then 1.7 else if ($g="D+") then 1.3 else if ($g="D") then 1.0 else if ($g="D-") then 0.7 else 0 }; declare function local:gpa($s) { fn:avg(for $g in return local:grade($g)) }; { for $s in fn:doc("students.xml")//student return }

Introduction to XLink Transparency No. 43 A Height Function Find the heigth of an node tree. declare function local:height($x) { if (fn:empty($x/*)) then 1 else fn:max(for $y in $x/* return local:height($y))+1 };

Introduction to XLink Transparency No. 44 A Textual Outline intended textual outline of a recipe unusual in that it generate plain text instead of xml output. Cailles en Sarcophages pastry chilled unsalted butter flour salt ice water filling baked chicken marinated chicken small chickens, cut up Herbes de Provence dry white wine orange juice minced garlic truffle oil...

Introduction to XLink Transparency No. 45 Computing Textual Outlines declare namespace rcp = " declare function local:ingredients($i,$p){ fn:string-join( (:$p is iden spaces :) for $j in $i/rcp:ingredient return ",local:ingredients($j,fn:concat($p," "))),""),"") }; declare function local:recipes($r) { fn:concat( $r/rcp:title/text()," ", local:ingredients($r," ")) }; fn:string-join( for $r in fn:doc("recipes.xml")//rcp:recipe[5] return local:recipes($r), ”” )

Introduction to XLink Transparency No. 46 Sequence Types 2 instance of xs:integer 2 instance of item() 2 instance of xs:integer? () instance of empty() () instance of xs:integer* (1,2,3,4) instance of xs:integer* (1,2,3,4) instance of xs:integer+ instance of item() instance of node() instance of element() instance of element(foo) instance of attribute() instance of attribute(bar) fn:doc("recipes.xml")//rcp:ingredient instance of element()+ fn:doc("recipes.xml")//rcp:ingredient instance of element(rcp:ingredient)+

Introduction to XLink Transparency No. 47 An Untyped Function declare function local:grade($g) { if ($g="A") then 4.0 else if ($g="A-") then 3.7 else if ($g="B+") then 3.3 else if ($g="B") then 3.0 else if ($g="B-") then 2.7 else if ($g="C+") then 2.3 else if ($g="C") then 2.0 else if ($g="C-") then 1.7 else if ($g="D+") then 1.3 else if ($g="D") then 1.0 else if ($g="D-") then 0.7 else 0 };

Introduction to XLink Transparency No. 48 A Default Typed Function declare function local:grade($g as item()*) as item()* { if ($g="A") then 4.0 else if ($g="A-") then 3.7 else if ($g="B+") then 3.3 else if ($g="B") then 3.0 else if ($g="B-") then 2.7 else if ($g="C+") then 2.3 else if ($g="C") then 2.0 else if ($g="C-") then 1.7 else if ($g="D+") then 1.3 else if ($g="D") then 1.0 else if ($g="D-") then 0.7 else 0 };

Introduction to XLink Transparency No. 49 A Precisely Typed Function declare function local:grade($g as xs:string) as xs:decimal { if ($g="A") then 4.0 else if ($g="A-") then 3.7 else if ($g="B+") then 3.3 else if ($g="B") then 3.0 else if ($g="B-") then 2.7 else if ($g="C+") then 2.3 else if ($g="C") then 2.0 else if ($g="C-") then 1.7 else if ($g="D+") then 1.3 else if ($g="D") then 1.0 else if ($g="D-") then 0.7 else 0 };

Introduction to XLink Transparency No. 50 Another Typed Function declare function local:grades($s as element(students)) as attribute(grade)* { };

Introduction to XLink Transparency No. 51 Runtime Type Checks Type annotations are checked during runtime A runtime type error is provoked when an actual argument value does not match the declared type a function result value does not match the declared type a valued assigned to a variable does not match the declared type

Introduction to XLink Transparency No. 52 Built-In Functions Have Signatures fn:contains($x as xs:string?, $y as xs:string?) as xs:boolean op:union($x as node()*, $y as node()*) as node()*

Introduction to XLink Transparency No. 53 XQueryX for $t in fn:doc("recipes.xml")/rcp:collection/rcp:recipe/rcp:title return $t <xqx:module xmlns:xqx=" xmlns:xsi=" xsi:schemaLocation=" xqueryx.xsd"> t doc recipes.xml child rcp:collection child rcp:recipe child xqx:nodeName> rcp:title t

Introduction to XLink Transparency No. 54 XML Databases How can XML and databases be merged? Several different approaches: extract XML views of relations use SQL to generate XML shred XML into relational databases

Introduction to XLink Transparency No. 55 The Student Database Again

Introduction to XLink Transparency No. 56 Automatic XML Views (1/2) Columns as attributes

Introduction to XLink Transparency No. 57 Automatic XML Views (2/2) Column as elements Joe Average Jack Doe 18

Introduction to XLink Transparency No. 58 Programmable Views wrap query results by xml elements SQL/XML xmlelement(name, "Students", select xmlelement(name, "record", xmlattributes(s.id, s.name, s.age)) from Students ) xmlelement(name, "Students", select xmlelement(name, "record", xmlforest(s.id, s.name, s.age)) from Students )

Introduction to XLink Transparency No. 59 XML Shredding Shredding an XML documents into multiple data base Tables Each element type is represented by a relation Each element node is assigned a unique key in document order so siblings can be ordered. Each element node contains the key of its parent so parent –child relations can be maintained The possible attributes are represented as fields, where absent attributes have the null value Contents consisting of a single character data node (#PCDATA only) is inlined as a field.

Introduction to XLink Transparency No. 60 From XQuery to SQL Any XML document can be faithfully represented This takes advantage of the existing database implementation Queries must now be phrased in ordinary SQL rather than XQuery But an automatic translation is possible select ingredient.amount from ingredient where ingredient.name="butter"

Introduction to XLink Transparency No. 61 Summary XML trees generalize relational tables XQuery similarly generalizes SQL XQuery and XSLT have roughly the same expressive power But they are suited for different application domains: data-centric vs. document-centric

Introduction to XLink Transparency No. 62 Essential Online Resources miplementations: