IS432 Semi-Structured Data Lecture 6: XQuery Dr. Gamal Al-Shorbagy.

Slides:



Advertisements
Similar presentations
1 Syntax-directed Transformations of XML Streams Stefanie Scherzinger joint work with Alfons Kemper.
Advertisements

Web Data Management XQuery 1. In this lecture Summary of XQuery FLWOR expressions – For, Let, Where, Order by, Return FOR and LET expressions Collections.
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.
2015/5/5 A Succinct Physical Storage Scheme for Efficient Evaluation of Path Queries in XML Ning Zhang(University of Waterloo) Varun Kacholia(Indian Institute.
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.
XQuery Or, what about REAL databases?. XQuery - its place in the XML team XLink XSLT XQuery XPath XPointer.
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.
1 XQuery Web and Database Management System. 2 XQuery XQuery is to XML what SQL is to database tables XQuery is designed to query XML data What is XQuery?
Database Management Systems, R. Ramakrishnan1 Introduction to Semistructured Data and XML Chapter 27, Part D Based on slides by Dan Suciu University of.
1 Part 3: Query Languages Managing XML and Semistructured Data.
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.
11/08/2002WIDM20021 An Algebraic Approach For Incremental Maintenance of Materialized XQuery Views Maged EL-Sayed, Ling Wang, Luping Ding, and Elke A.
Xquery Introduction by Examples. Sources XQuery 1.0: An XML Query LanguageW3C Working Draft 22 August 2003 Don Chamberlin’s Sigmod03 talk:
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.
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
1 Lecture 9: XQuery. 2 XQuery Motivation XPath expressivity insufficient –no join queries (as in SQL) –no changes to the XML structure possible –no quantifiers.
1 Efficient XML Stream Processing with Automata and Query Algebra A Master Thesis Presentation Student: Advisor: Reader: Jinhui Jian Prof. Elke A. Rundensteiner.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 357 Database Systems I Query Languages for XML.
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.
Managing XML and Semistructured Data Lecture 6: XPath Prof. Dan Suciu Spring 2001.
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.
4/15/2002Bo Du 1 - Bo Du, April 15, XML - QL A Query Language for XML.
XML QUERY LANGUAGE Prepared by Prof. Zaniolo, Hung-chih Yang, Ling-Jyh Chen Modified by Fernando Farfán.
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.
1 Lecture 08: XML and Semistructured Data. 2 Outline XML (Section 17) –XML syntax, semistructured data –Document Type Definitions (DTDs) XPath.
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:
1 Lecture 16: Querying XML Data: XPath, XQuery Friday, February 11, 2005.
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.
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:
1 XQuery Slides From Dr. Suciu. 2 FLWR (“Flower”) Expressions FOR... LET... WHERE... RETURN... FOR... LET... WHERE... RETURN...
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.
1 XTree for Declarative XML Querying Zhuo Chen, Tok Wang Ling, Mengchi Liu, and Gillian Dobbie January 2004.
Introduction to XQuery Bun Yue Professor, CS/CIS UHCL.
Lecture 6: XML Query Languages Thursday, January 18, 2001.
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 query. introduction An XML document can represent almost anything, and users of an XML query language expect it to perform useful queries on whatever.
SDPL 20077: Querying XML with XQuery1 7 Querying XML n How to access XML data sources? n XQuery, XML Query Lang, W3C Rec, 01/ '07 –joint work by XML Query.
Submitted To: Ms. Poonam Saini, Asst. Prof., NITTTR Submitted By: Rohit Handa ME (Modular) CSE 2011 Batch.
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 May 6th, Instructor AnHai Doan Brief bio –high school in Vietnam & undergrad in Hungary –M.S. at Wisconsin –Ph.D. at Washington under Alon &
XQuery 1. In this lecture Summary of XQuery FLWOR expressions – For, Let, Where, Order by, Return FOR and LET expressions Collections and sorting 2.
Lecture 17: XPath and XQuery Wednesday, Nov. 7, 2001.
1 Lecture 12: XML, XPath, XQuery Friday, October 24, 2003.
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.
XQUERY The contents of this slide are obtained from various sources including, Wikipedia, W3School, Stanford website etc. January 2011 Dr.Kwanchai Eurviriyanukul.
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.
Session IV Chapter 16 – XQuery
8 Querying XML How to access different sources (DBs, docs) as XML?
Lecture 12: XML, XPath, XQuery
Semi-Structured data (XML Data MODEL)
Lecture 9: XML Monday, October 17, 2005.
Xquery Slides From Dr. Suciu.
Lecture 15: Querying XML Friday, October 27, 2000.
Session II Chapter 16 – XQuery
Presentation transcript:

IS432 Semi-Structured Data Lecture 6: XQuery Dr. Gamal Al-Shorbagy

Introduction What is XQuery? - XQuery is to XML what SQL is to database tables. - XQuery was designed to query XML data. - XQuery is built on XPath expressions - XQuery is supported by all major databases - XQuery is a W3C Recommendation

Introduction XQuery can be used to: - Extract information to use in a Web Service - Generate summary reports - Transform XML data to XHTML - Search Web documents for relevant information

FLWR (“Flower”) Expressions for $x in doc("bib.xml")/bib/book where $x/price>30 order by $x/title return $x/title FLWOR is an acronym for "For, Let, Where, Order by, Return". The for clause selects all book elements under the bib element into a variable called $x. The where clause selects only book elements with a price element with a value greater than 30. The order by clause defines the sort-order. Will be sort by the title element. The return clause specifies what should be returned. Here it returns the title elements.

FOR v.s. LET FOR Binds node variables  iteration LET Binds collection variables  one value

Bib.xml TCP/IP Illustrated Stevens W. Addison-Wesley Advanced Programming in the Unix environment Stevens W. Addison-Wesley Data on the Web Abiteboul Serge Buneman Peter Suciu Dan Morgan Kaufmann Publishers The Economics of Technology and Content for Digital TV Gerbarg Darcy CITI Kluwer Academic Publishers

Bib.dtd

Books.xml Data Model Syntax For Data Model XML Basic Syntax XML and Semistructured Data

Books.xml

Reviews.xml Data on the Web A very good discussion of semi-structured database systems and XML. Advanced Programming in the Unix environment A clear and detailed discussion of UNIX programming. TCP/IP Illustrated One of the best books on TCP/IP.

Reviews.dtd

Prices.xml Advanced Programming in the Unix environment bstore2.example.com Advanced Programming in the Unix environment bstore1.example.com TCP/IP Illustrated bstore2.example.com TCP/IP Illustrated bstore1.example.com Data on the Web bstore2.example.com Data on the Web bstore1.example.com 39.95

Prices.dtd

Query 1 List books published by Addison-Wesley after 1991, including their year and title { for $b in doc("bib.xml")/bib/book where $b/publisher = "Addison-Wesley" and > 1991 return { $b/title } } The doc() function is used to open the “bib.xml" TCP/IP Illustrated <book year="1992"> Advanced Programming in the Unix environment

Query 2 Create a flat list of all the title-author pairs, with each pair enclosed in a "result" element. {for $b in doc("bib.xml")/bib/book, $t in $b/title, $a in $b/author return { $t } { $a } } TCP/IP Illustrated Stevens W. Advanced Programming in the Unix environment Stevens W. Data on the Web Abiteboul Serge Data on the Web Buneman Peter Data on the Web Suciu Dan

Query 3 For each book in the bibliography, list the title and authors, grouped inside a "result" element. { for $b in doc("bib.xml")/bib/book return { $b/title } { $b/author } } TCP/IP Illustrated Stevens W. Advanced Programming in the Unix environment Stevens W. Data on the Web Abiteboul Serge Buneman Peter Suciu Dan The Economics of Technology and Content for Digital TV

Query 4 For each author in the bibliography, list the author's name and the titles of all books by that author, grouped inside a "result" {let $a := doc("bib.xml")//author for $last in distinct-values($a/last), $first in distinct-values($a[last=$last]/first) order by $last, $first return { $last } { $first } {for $b in doc("bib.xml")/bib/book where some $ba in $b/author satisfies ($ba/last = $last and $ba/first=$first) return $b/title} }

Query 4 Abiteboul Serge Data on the Web Buneman Peter Data on the Web Stevens W. TCP/IP Illustrated Advanced Programming in the Unix environment Suciu Dan Data on the Web

Query 5 For each book found in bib.xml and reviews.xml, list the title of the book and its price from each source { for $b in doc("bib.xml")//book, $a in doc("reviews.xml")//entry where $b/title = $a/title return { $b/title } { $a/price/text() } { $b/price/text() } } TCP/IP Illustrated 65.95</price- reviews-source> <book-with- prices> Advanced Programming in the Unix environment Data on the Web

Query 6 For each book that has at least one author, list the title and first two authors, and an empty "et-al" element if the book has additional authors. {for $b in doc("bib.xml")//book where count($b/author) > 0 return { $b/title } {for $a in $b/author[position()<=2] return $a} {if (count($b/author) > 2) then else ()} }

Query 6 TCP/IP Illustrated Stevens W. Advanced Programming in the Unix environment Stevens W. Data on the Web Abiteboul Serge Buneman Peter

Query 7 List the titles and years of all books published by Addison-Wesley after 1991, in alphabetic order. { for $b in doc("bib.xml")//book where $b/publisher = "Addison-Wesley" and > 1991 order by $b/title return { $b/title } } Advanced Programming in the Unix environment TCP/IP Illustrated

Query 8 Find books in which the name of some element ends with the string "or" and the same element contains the string "Suciu" somewhere in its content. For each such book, return the title and the qualifying element. for $b in doc("bib.xml")//book let $e := $b/*[contains(string(.), "Suciu") and ends-with(local-name(.), "or")] where exists($e) return { $b/title } { $e } Data on the Web Suciu Dan

Query 9 In the document "books.xml", find all section or Section titles that contain the word "XML", regardless of the level of nesting { for $t in doc("books.xml")//(Section | section)/title where contains($t/text(), "XML") return $t } XML XML and Semistructured Data

Query 10 In the document "prices.xml", find the minimum price for each book, in the form of a "minprice" element with the book title as its title attribute. { let $doc := doc("prices.xml") for $t in distinct-values($doc//book/title) let $p := $doc//book[title = $t]/price return { min($p) } }

Query 11 For each book with an author, return the book with its title and authors. For each book with an editor, return a reference with the book title and the editor's affiliation. {for $b in doc("bib.xml")//book[author] return {$b/title } {$b/author } } {for $b in doc("bib.xml")//book[editor] return {$b/title } {$b/editor/affiliation} }

Query 11 TCP/IP Illustrated Stevens W. Advanced Programming in the Unix environment Stevens W. Data on the Web Abiteboul Serge Buneman Peter Suciu Dan The Economics of Technology and Content for Digital TV CITI

Query 12 Find pairs of books that have different titles but the same set of authors (possibly in a different order) {for $book1 in doc("bib.xml")//book, $book2 in doc("bib.xml")//book let $aut1 := for $a in $book1/author order by $a/last, $a/first return $a let $aut2 := for $a in $book2/author order by $a/last, $a/first return $a where $book1 << $book2 and not($book1/title = $book2/title) and deep-equal($aut1, $aut2) return { $book1/title } { $book2/title } }

Query 12 TCP/IP Illustrated Advanced Programming in the Unix environment

Thanks