Presentation is loading. Please wait.

Presentation is loading. Please wait.

Advisor: Prof. Zaniolo Hung-chih Yang Ling-Jyh Chen XML Query Language.

Similar presentations


Presentation on theme: "Advisor: Prof. Zaniolo Hung-chih Yang Ling-Jyh Chen XML Query Language."— Presentation transcript:

1 Advisor: Prof. Zaniolo Hung-chih Yang Ling-Jyh Chen XML Query Language

2 Motivation As increasing amounts of information are stored, exchanged, and presented using XML, the ability to intelligently query XML data sources becomes increasingly important. One of the great strengths of XML is its flexibility in representing many different kinds of information from diverse sources. To exploit this flexibility, an XML query language must provide features for retrieving and interpreting information from these diverse sources.

3 Desiderata for an XML query language Expressive power Semantics Compositionality Schema Program manipulation

4 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

5 What’s XQuery Relational database SQL XML document /database XQuery

6 What’s XQuery (cont.) XQuery is designed to meet the requirements identified by the W3C XML Query Working Group “XML Query 1.0 Requirements” and the use cases in “XML Query Use Cases”. XQuery is designed to be a small, easily implementable language. XQuery is flexible enough to query a broad spectrum of XML information sources, including both databases and documents. XQuery defines a human-readable syntax for that language

7 What’s Xquery (cont.) The basic building block of XQuery is the expression XQuery is a functional language (at least the spec claimed it to be) XQuery is a strongly-typed language

8 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

9 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

10 The principal forms of XQuery expressions Primary –The basic primitives of the language including literals, variables, function calls and the use of parentheses to control precedence of operation 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.

11 The principal forms of XQuery expressions (cont.) Arithmetic –Xquery provides arithmetic operators for addition, subtraction, multiplication, division, and modulus. Comparison –Xquery provides 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 one of the boolean values: true or false.

12 The principal forms of XQuery expressions (cont.) Contructor –Constructors can create XML structures within a query. There are constructors for elements, attributes, CDATA sections, processing instructions, and comments. FLWR –XQuery provides a FLWR expression for iteration and for binding variables to intermediate results. This kind of expression is often useful for computing joins between two or more documents and for restructuring data. The name "FLWR", pronounced "flower", stands for the keywords for, let, where, and return, the four clauses found in a FLWR expression.

13 The principal forms of XQuery expressions (cont.) Sorting –A sorting expression provides a way to control the order of items in a sequence. Conditional –XQuery supports a conditional expression based on the keywords if, then, and else. Quantified –Quantified expressions support existential and universal quantification. The value of a quantified expression is always true or false.

14 The principal forms of XQuery expressions (cont.) Datatypes –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.

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

16 XQuery Example 2 document("bib.xml")/bib/book[@year < 1995]/title XQuery: Find the title of all books published before 1995 Result: TCP/IP Illustrated Advanced Programming in the Unix environment

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

18 XQuery Example 3 (for loop) TCP/IP Illustrated Advanced Programming in the Unix environment Result:

19 XQuery Example 4 (Join) { 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 } } XQuery: For each book found at both bn.com and amazon.com, list the title of the book and its price from each source.

20 XQuery Example 4 (Join) TCP/IP Illustrated 65.95 Advanced Programming in the Unix environment 65.95 Data on the Web 34.95 39.95 Result:

21 XQuery Example 5 ( Grouping + quantifier ) { for $a in distinct-values(document("bib.com")//author) return { $a } { for $b in document("http://bib.com")/bib/book where some $ba in $b/author satisfies deep-equal($ba,$a) return $b/title } } XQuery: 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.

22 XQuery Example 5 ( Grouping + quantifier ) Stevens W. TCP/IP Illustrated Advanced Programming in the Unix environment Abiteboul Serge Data on the Web …… Result:

23 XQuery Example 6 (Sorting) { for $b in document("www.bn.com/bib.xml")//book where $b/publisher = "Addison-Wesley" and $b/@year > 1991 return { $b/@year } { $b/title } sortby (title) } XQuery: List the titles and years of all books published by Addison- Wesley after 1991, in alphabetic order.

24 XQuery Example 6 (Sorting) Advanced Programming in the Unix environment TCP/IP Illustrated Result:

25 XQuery Example 7 (Recursion) define function one_level (element $p) returns element { { for $s in document("partlist.xml")//part where $s/@partof = $p/@partid return one_level($s) } } { for $p in document("partlist.xml")//part[empty(@partof)] return one_level($p) } XQuery: Convert the sample document from "partlist" format to "parttree" format.

26 XQuery Example 7 (Recursion) Result:

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

28 XQuery practice XML Query Language Demo, http://131.107.228.20 X-Hive. Another nice-looking online demo, http://217.77.130.189:8080/demos/xquery/index.html Qexo: The GNU Kawa implementation of XQuery, http://www.gnu.org/software/qexo/

29 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 simplier 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

30 Reference Jonathan Pinnock, et al. “Professional XML, 2 nd edition”, ISBN: 1861005059, WROX Publishers, 2001 Serge Abiteboul, Peter Buneman and Dan Suciu, “Data on the Web: from Relations to Semistructured Data and XML”, ISBN 1-55860-622-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, http://www.gnu.org/software/qexo/ XQuery Tutorial http://www.research.avayalabs.com/user/wadler/papers/xquery-tutorial/xquery-tutorial.pdf Don Chamberlin, Jonathan Robie, and Daniela Florescu, “Quilt: An XML Query Language for Heterogeneous Data Sources”, WebDB 2000, Dallas, May 2000


Download ppt "Advisor: Prof. Zaniolo Hung-chih Yang Ling-Jyh Chen XML Query Language."

Similar presentations


Ads by Google