XML QUERY LANGUAGE Prepared by Prof. Zaniolo, Hung-chih Yang, Ling-Jyh Chen Modified by Fernando Farfán.

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

XQuery How to handle databases with the XML standard? Peter van Keeken Industrial trainee, Evitech 4 th period 2002.
XML: Extensible Markup Language
XML May 3 rd, XQuery Based on Quilt (which is based on XML-QL) Check out the W3C web site for the latest. XML Query data model –Ordered !
XML, XML Schema, Xpath and XQuery Slides collated from various sources, many from Dan Suciu at Univ. of Washington.
XQUERY. What is XQuery? XQuery is the language for querying XML data The best way to explain XQuery is to say that XQuery is to XML what SQL is to database.
Database Management Systems, R. Ramakrishnan1 Introduction to Semistructured Data and XML Chapter 27, Part D Based on slides by Dan Suciu University of.
Agenda from now on Done: SQL, views, transactions, conceptual modeling, E/R, relational algebra. Starting: XML To do: the database engine: –Storage –Query.
© 2002 by Prentice Hall 1 SI 654 Database Application Design Winter 2003 Dragomir R. Radev.
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.
Managing XML and Semistructured Data Lecture 8: Query Languages - XML-QL Prof. Dan Suciu Spring 2001.
Querying XML (cont.). Comments on XPath? What’s good about it? What can’t it do that you want it to do? How does it compare, say, to SQL?
IS432: Semi-Structured Data Dr. Azeddine Chikh. 7. XQuery.
1 Lecture 10 XML Wednesday, October 18, XML Outline XML (4.6, 4.7) –Syntax –Semistructured data –DTDs.
XQuery: 1 W3C (World Wide Web Consortium) What is W3C? –An industry consortium, best known for standardizing HTML and XML. –Working Groups create or adopt.
A Graphical Environment to Query XML Data with XQuery
Query Languages Aswin Yedlapalli. XML Query data model Document is viewed as a labeled tree with nodes Successors of node may be : - an ordered sequence.
XQuery language Presented by: Tayeb sbihi supervised by: Dr. H. Haddouti.
1 COS 425: Database and Information Management Systems XML and information exchange.
Query Languages - XQuery Slides partially from Dan Suciu.
XML and The Relational Data Model
XML May 1 st, XML for Representing Data John 3634 Sue 6343 Dick 6363 John 3634 Sue 6343 Dick 6363 row name phone “John”3634“Sue”“Dick” persons.
XQuery – The W3C XML Query Language Jonathan Robie, Software AG Don Chamberlin, IBM Research Daniela Florescu, INRIA.
XML Introduction What is XML –XML is the eXtensible Markup Language –Became a W3C Recommendation in 1998 –Tag-based syntax, like HTML –You get to make.
XML –Query Languages, Extracting from Relational Databases ADVANCED DATABASES Khawaja Mohiuddin Assistant Professor Department of Computer Sciences Bahria.
Introduction to Structured Query Language (SQL)
Fundamentals, Design, and Implementation, 9/e Text and XML databases Instructor: Dragomir R. Radev Winter 2005.
XML, XML Schema, XPath and XQuery Query Languages CS561 Slides collated from several sources, including D. Suciu at Univ. of Washington.
Xpath to XQuery February 23rd, Other Stuff HW 3 is out. Instructions for Phase 3 are out. Today: finish Xpath, start and finish Xquery. From Wednesday:
Querying XML February 12 th, Querying XML Data XPath = simple navigation through the tree XQuery = the SQL of XML XSLT = recursive traversal –will.
Processing of structured documents Spring 2003, Part 8 Helena Ahonen-Myka.
Introduction to XPath Bun Yue Professor, CS/CIS UHCL.
4/20/2017.
XQuery Your gateway to manipulating XML in SQL Server 2005.
Advisor: Prof. Zaniolo Hung-chih Yang Ling-Jyh Chen XML Query Language.
Xquery. Summary of XQuery FLWR expressions FOR and LET expressions Collections and sorting Resource W3C recommendation:
Introduction to XQuery Resources: Official URL: Short intros:
SDPL 20067: Querying XML with XQuery1 7 Querying XML n How to access data sources as XML? n XQuery, W3C XML Query Language –Candidate Rec, November 2005.
XML and XPath. Web Services: XML+XPath2 EXtensible Markup Language (XML) a W3C standard to complement HTML A markup language much like HTML origins: structured.
1 XML INTEROPERABILITY Manjusha Ravindranath. 2 CONTENTS Introduction Interoperability XSSQL syntax Usecases document Group By -Without aggregation -With.
Introduction to XML and XQuery Guangjun (Kevin) Xie.
TDDD43 XML and RDF Slides based on slides by Lena Strömbäck and Fang Wei-Kleiner 1.
1 XTree for Declarative XML Querying Zhuo Chen, Tok Wang Ling, Mengchi Liu, and Gillian Dobbie January 2004.
DATABASE and XML Moussa Mané. Learning Objectives ● Learn about Native XML Databases ● Learn about the conversion technology available ● Understand New.
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.
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.
Extensible Markup and Beyond
A Quilt, not a Camel Don Chamberlin Jonathan Robie Daniela Florescu May 19, 2000.
Introduction to XQuery Bun Yue Professor, CS/CIS UHCL.
SDPL 2002Notes 9: XQuery1 9 Querying XML Data and Documents n XQuery, W3C XML Query Language –"work in progress", Working Draft, 30 April 2002 –joint work.
XML Databases by Sebastian Graf Hier beginnt mein toller Vortrag.
[ Part III of The XML seminar ] Presenter: Xiaogeng Zhao A Introduction of XQL.
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.
1 XQuery Slides From Dr. Suciu. 2 XQuery Based on Quilt, which is based on XML-QL Uses XPath to express more complex queries.
XML Query: xQuery Reference: Xquery By Priscilla Walmsley, Published by O’Reilly.
XML May 6th, Instructor AnHai Doan Brief bio –high school in Vietnam & undergrad in Hungary –M.S. at Wisconsin –Ph.D. at Washington under Alon &
IS432 Semi-Structured Data Lecture 6: XQuery Dr. Gamal Al-Shorbagy.
XPath --XML Path Language Motivation of XPath Data Model and Data Types Node Types Location Steps Functions XPath 2.0 Additional Functionality and its.
CSE 6331 © Leonidas Fegaras XQuery 1 XQuery Leonidas Fegaras.
Lecture 17: XPath and XQuery Wednesday, Nov. 7, 2001.
SEMI-STRUCTURED DATA (XML) 1. SEMI-STRUCTURED DATA ER, Relational, ODL data models are all based on schema Structure of data is rigid and known is advance.
SDPL 2005Notes 7: XQuery1 7 Querying XML n How to access different sources (DBs, docs) as XML? n XQuery, W3C XML Query Language –"work in progress", (last.
XML: Extensible Markup Language
Querying and Transforming XML Data
Querying XML and Semistructured Data
{ XML Technologies } BY: DR. M’HAMED MATAOUI
Semi-Structured data (XML Data MODEL)
Lecture 9: XML Monday, October 17, 2005.
XQuery Leonidas Fegaras.
Semi-Structured data (XML)
Presentation transcript:

XML QUERY LANGUAGE Prepared by Prof. Zaniolo, Hung-chih Yang, Ling-Jyh Chen Modified by Fernando Farfán

Motivation  Increasing amounts of information stored, exchanged, and presented as XML.  Ability to intelligently query XML data sources.  XML strength: Flexibility representing many kinds of information from diverse sources.  XML query language must retrieve and interpret information from these diverse sources. 2 XML Query Language Tutorial

Desiderata for an XML Query Language  Expressive power  Semantics  Compositionality  Schema  Program manipulation 3 XML Query Language Tutorial

Different Query Languages for XML  XPath & XQL: path expression syntax suitable for hierarchical documents  XML-QL: binding variables and using bound variables to create new structures  SQL: SELECT-FROM-WHERE pattern for restructuring data  OQL: ODMG  Quilt: accept a lot of advantages from above XML query languages, and it’s the immediate ancestor of XQuery 4 XML Query Language Tutorial

What is XQuery 5 XML Query Language Tutorial

What is XQuery (cont.)  Designed to meet the requirements identified by the W3C XML Query Working Group  “XML Query 1.0 Requirements”  “XML Query Use Cases”.  Designed to be a small, easily implementable language.  Flexible enough to query a broad spectrum of XML sources (both databases and documents).  Defines a human-readable syntax for that language. 6 XML Query Language Tutorial

What is XQuery (cont.)  Expression: Basic building block.  Functional language (at least claimed by the spec.)  Strongly-typed language. 7 XML Query Language Tutorial

XQuery vs. XSLT Reinventing the Wheel?  XSLT is document-driven; XQuery is program driven.  XSLT is written in XML; XQuery is not.  An assertion (unproven): XSLT 2.0 can do everything XQuery can do. 8 XML Query Language Tutorial

XQuery Concepts  A query in XQuery is an expression that:  Reads a number of XML documents or fragments  Returns a sequence of well-formed XML fragments 9 XML Query Language Tutorial

The Principal Forms of XQuery Expressions  Primary  Literals, variables, function calls and parentheses (for control precedence).  Path  Locates nodes within a tree, and returns a sequence of distinct nodes in document order.  Sequence  An ordered collection of zero or more items, where an item may be an atomic value or a node.  An item is identical to a sequence of length one containing that item. Sequences are never nested. 10 XML Query Language Tutorial

The Principal Forms of XQuery Expressions (Cont.)  Arithmetic  Arithmetic operators for addition, subtraction, multiplication, division, and modulus.  Comparison  Four kinds of comparisons: value, general, node, and order comparisons.  Logical  A logical expression is either an AND-expression or an OR- expression.  The value of a logical expression is always a Boolean value. 11 XML Query Language Tutorial

The Principal Forms of XQuery Expressions (Cont.)  Constructor  Constructors can create XML structures within a query.  There are constructors for elements, attributes, CDATA sections, processing instructions, and comments.  FLWR  Expression for iteration and for binding variables to intermediate results.  Useful for computing joins between two or more documents and for restructuring data.  Pronounced "flower", stands for the keywords FOR, LET, WHERE, and RETURN, the four clauses found in a FLWR expression. 12 XML Query Language Tutorial

The Principal Forms of XQuery Expressions (Cont.)  Sorting expressions  Provides a way to control the order of items in a sequence.  Conditional expressions  Based on the keywords IF, THEN, and ELSE.  Quantified expressions  support existential and universal quantification.  The value of a quantified expression is always true or false. 13 XML Query Language Tutorial

The Principal Forms of XQuery Expressions (Cont.)  Data types  Runtime type checking and manipulation  Validate  A validate expression validates its argument with respect to the in-scope schema definitions, using the schema validation process described in XML Schema. 14 XML Query Language Tutorial

XQuery Example 1  Find all books with a price of $39.95 XQuery: document("bib.xml")/bib/book[price = 39.95] Result: Data on the Web Abiteboul Serge Buneman Peter Suciu Dan Morgan Kaufmann Publishers XML Query Language Tutorial

XQuery Example 2  Find the title of all books published before 1995 XQuery: < 1995]/title Result: TCP/IP Illustrated Advanced Programming in the Unix environment 16 XML Query Language Tutorial

XQuery Example 3 (For Loop)  List books published by Addison-Wesley after 1991, including their year and title. XQuery: { for $b in document("bib.xml")/bib/book where $b/publisher = "Addison-Wesley" and > 1991 return { $b/title } } 17 XML Query Language Tutorial

XQuery Example 3 (For Loop)  List books published by Addison-Wesley after 1991, including their year and title… Result: TCP/IP Illustrated Advanced Programming in the Unix environment 18 XML Query Language Tutorial

XQuery Example 4 (Join)  For each book found at both bn.com and amazon.com, list the title of the book and its price from each source. XQuery: { for $b in document("bib.xml")//book, $a in document("reviews.xml")//entry where $b/title = $a/title return { $b/title } { $a/price } { $b/price } } 19 XML Query Language Tutorial

XQuery Example 4 (Join)  For each book found at both bn.com and amazon.com, list the title of the book and its price from each source. Result: TCP/IP Illustrated Advanced Programming in the Unix environment Data on the Web XML Query Language Tutorial

XQuery Example 5 ( Grouping + quantifier )  For each author in the bibliography, list the author's name and the titles of all books by that author, grouped inside a "result" element. XQuery: { for $a in distinct-values(document("bib.com")//author) return { $a } { for $b in document(" where some $ba in $b/author satisfies deep-equal($ba,$a) return $b/title } } 21 XML Query Language Tutorial

XQuery Example 5 ( Grouping + quantifier )  For each author in the bibliography, list the author's name and the titles of all books by that author, grouped inside a "result" element. Result: Stevens W. TCP/IP Illustrated Advanced Programming in the Unix environment Abiteboul Serge Data on the Web …… 22 XML Query Language Tutorial

XQuery Example 6 (Sorting)  List the titles and years of all books published by Addison-Wesley after 1991, in alphabetic order. XQuery: { for $b in document(" where $b/publisher = "Addison-Wesley" and > 1991 return { } { $b/title } sortby (title) } 23 XML Query Language Tutorial

XQuery Example 6 (Sorting)  List the titles and years of all books published by Addison-Wesley after 1991, in alphabetic order. Result: Advanced Programming in the Unix environment TCP/IP Illustrated 24 XML Query Language Tutorial

XQuery Example 7 (Recursion)  Convert the sample document from "partlist" format to "parttree" format. XQuery: define function one_level (element $p) returns element { { for $s in document("partlist.xml")//part where = return one_level($s) } } { for $p in return one_level($p) } 25 XML Query Language Tutorial

XQuery Example 7 (Recursion)  Convert the sample document from "partlist" format to "parttree" format. Result: 26 XML Query Language Tutorial

XQuery Example 8 (Sequence)  In the Procedure section of Report1, what Instruments were used in the second Incision? XQuery: for $s in document("report1.xml")//section[section.title = "Procedure"] return ($s//incision)[2]/instrument Result: electrocautery 27 XML Query Language Tutorial

XQuery Support on RDBMSs XML Query Language Tutorial 28  Oracle XQuery Engine   Introduction to XQuery in SQL Server 2005  us/library/ms345122(SQL.90).aspx  Query DB2 XML data with XQuery  dm-0604saracco/  DataDirect: Data Integration Suite – MySQL Database Support  integration/datasources/databases/mysql/index.ssp

Conclusion  XQuery is a simple substitution of XSLT, JSP, ASP, Servlet, CGI, PHP, etc.  XQuery programs can accomplish most tasks of other tools aforementioned, and yet is much simpler to learn and easier to write.  Possible direction is to extend XQuery for UPDATE and INSERT to an XML database  Still lack of support from industry till now 29 XML Query Language Tutorial

References  Jonathan Pinnock, et al. “Professional XML, 2nd edition”, ISBN: , WROX Publishers, 2001  Serge Abiteboul, Peter Buneman and Dan Suciu, “Data on the Web: from Relations to Semistructured Data and XML”, ISBN X, Morgan Kaufmann Publishers, 2000  World Wide Web Consortium, “XQuery 1.0. An XML Query Language”, W3C Working Draft, Apr. 30, 2002  World Wide Web Consortium, “XML Path Language (XPath) Version 1.0”, W3C Recommendation, Nov. 16, 1999  Qexo: The GNU Kawa implementation of XQuery,  Don Chamberlin, Jonathan Robie, and Daniela Florescu, “Quilt: An XML Query Language for Heterogeneous Data Sources”, WebDB 2000, Dallas, May XML Query Language Tutorial