XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302

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

Querying on the Web: XQuery, RDQL, SparQL Semantic Web - Spring 2006 Computer Engineering Department Sharif University of Technology.
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 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?
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.
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
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?
By relieving the brain of all unnecessary work, a good notation sets it free to concentrate on more advanced problems, and, in effect, increases the mental.
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
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.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 357 Database Systems I Query Languages for XML.
1 COS 425: Database and Information Management Systems XML and information exchange.
SDPL 2001Notes 8.2: XQuery1 8.2 W3C XML Query Language –Thanks for Helena Ahonen-Myka (University of Helsinki) for borrowing her slide originals for this.
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 Languages, Extracting from Relational Databases ADVANCED DATABASES Khawaja Mohiuddin Assistant Professor Department of Computer Sciences Bahria.
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
Processing of structured documents Spring 2003, Part 8 Helena Ahonen-Myka.
Advanced Database CS-426 Week 2 – Logic Query Languages, Object Model.
XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: Introduction.
Lecture 7 of Advanced Databases XML Querying & Transformation Instructor: Mr.Ahmed Al Astal.
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.
XML-QL A Query Language for XML Charuta Nakhe
Structured-Document Processing Languages Spring 2011 Course Review Repetitio mater studiorum est!
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.
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.
XML Overview. Chapter 8 © 2011 Pearson Education 2 Extensible Markup Language (XML) A text-based markup language (like HTML) A text-based markup language.
CSE314 Database Systems More SQL: Complex Queries, Triggers, Views, and Schema Modification Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
Lecture 05 Structured Query Language. 2 Father of Relational Model Edgar F. Codd ( ) PhD from U. of Michigan, Ann Arbor Received Turing Award.
1 XSLT An Introduction. 2 XSLT XSLT (extensible Stylesheet Language:Transformations) is a language primarily designed for transforming the structure of.
1 What’s in This Module? Semistructured data XML & DTD – introduction XML Schema – user-defined data types, integrity constraints XPath & XPointer – core.
Database Systems Part VII: XML Querying Software School of Hunan University
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.
1 Relational Algebra and Calculas Chapter 4, Part A.
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.
IS 230Lecture 6Slide 1 Lecture 7 Advanced SQL Introduction to Database Systems IS 230 This is the instructor’s notes and student has to read the textbook.
1 Relational Algebra Chapter 4, Sections 4.1 – 4.2.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 4 Relational Algebra.
CS 157B: Database Management Systems II February 11 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
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.
This PowerPoint is based on slides from: Rajshekhar Sunderraman, Department of Computer Science Georgia State University.
CSE 6331 © Leonidas Fegaras XQuery 1 XQuery Leonidas Fegaras.
Lecture 17: XPath and XQuery Wednesday, Nov. 7, 2001.
1 Schema for Student Registration System Student Student (Id, Name, Addr, Status) Professor Professor (Id, Name, DeptId) Course Course (DeptId, CrsCode,
Database Management Systems, R. Ramakrishnan1 Introduction to Semistructured Data and XML Chapter 27.
1 Chapter 15 XML and Web Data. 2 What’s in This Module? Semistructured data XML & DTD – introduction XML Schema – user-defined data types, integrity constraints.
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.
Introduction to Semistructured Data and XML. How the Web is Today HTML documents – often generated by applications – consumed by humans only – easy access:
More SQL: Complex Queries, Triggers, Views, and Schema Modification
XML: Extensible Markup Language
More SQL: Complex Queries,
XML Technologies and Applications
Chapter 3 Introduction to SQL(3)
CS 480: Database Systems Lecture 28 March 22, 2013.
SQL: Advanced Options, Updates and Views Lecturer: Dr Pavle Mogin
Chapter 12 Outline Overview of Object Database Concepts
Instructor: Mohamed Eltabakh
More SQL: Complex Queries, Triggers, Views, and Schema Modification
XQuery Leonidas Fegaras.
Presentation transcript:

XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA V (c). XML Querying: XQuery December 2005

Outline  Introduction  XML Basics  XML Structural Constraint Specification  Document Type Definitions (DTDs)  XML Schema  XML/Database Mappings  XML Parsing APIs  Simple API for XML (SAX)  Document Object Model (DOM)  XML Querying and Transformation  XPath  XSLT  XQuery  XML Applications

XQuery – XML Query Language Integrates XPath with earlier proposed query languages: XQL, XML-QL SQL-style, not functional-style Much easier to use as a query language than XSLT Can do pretty much the same things as XSLT and more, but typically easier 2004: XQuery 1.0

transcript.xml … … cont’d … …

transcript.xml (cont’d)

XQuery Basics General structure (FLWR expressions): FOR variable declarations LET variable := expression, variable := expression, … WHERE condition RETURN document Example: (: students who took MAT123 :) FOR $t IN doc(“ WHERE = “MAT123” RETURN $t/Student Result: XQuery expression comment

XQuery Basics (cont’d) Previous query doesn’t produce a well-formed XML document; the following does: { FOR $t IN doc(“transcript.xml”)//Transcript WHERE = “MAT123” RETURN $t/Student } Transcript StudentStudentListFOR binds $t to Transcript elements one by one, filters using WHERE, then places Student-children as e-children of StudentList using RETURN Query inside XML

FOR vs LET FOR $x IN doc(“transcript.xml”) RETURN { $x } FOR $x IN doc(“transcript.xml”) RETURN { $x } Returns: LET $x := doc(“transcript.xml”) RETURN { $x } LET $x := doc(“transcript.xml”) RETURN { $x } Returns:... For: iteration Let: set value is assigned to variable.

Document Restructuring with XQuery Transcript Reconstruct lists of students taking each class using the Transcript records: FOR $c IN distinct values(doc(“transcript.xml”)//CrsTaken) RETURN { FOR $t IN doc(“transcript.xml”)//Transcript WHERE = = RETURN $t/Student ORDER BY } ORDER BY Query inside RETURN – similar to query inside SELECT in OQL

Document Restructuring (cont’d) Output elements have the form: Problem: the above element will be output twice – for each of the following two bindings of $c: Note: grades are different – distinct-values( ) won’t eliminate transcript records that refer to same class! John Doe’s Bart Simpson’s

Document Restructuring (cont’d) Solution: instead of FOR $c IN distinct-values(doc(“transcript.xml”)//CrsTaken) use classes.xml FOR $c IN doc(“classes.xml”)//Class classes.xml where classes.xml lists course offerings (course code/semester) explicitly (no need to extract them from transcript records) – shown on next slide Then $c is bound to each class exactly once, so each class roster will be output exactly once

SE Adrian Jones Circuits David Jones Databases Mary Doe TP John Smyth Algebra Ann White

Document Restructuring (cont’d) More problems: the above query will list classes with no students. Reformulation that avoids this: FOR $c IN doc(“classes.xml”)//Class WHERE = = RETURN { FOR $t IN doc(“transcript.xml”)//Transcript WHERE = = RETURN $t/Student ORDER BY } ORDER BY Test that classes aren’t empty

XQuery Semantics So far the discussion was informal XQuery semantics defines what the expected result of a query is Defined analogously to the semantics of SQL

XQuery Semantics (cont’d) Step 1: Produce a list of bindings for variables –The FOR clause binds each variable to a list of nodes specified by an XQuery expression. The expression can be: An XPath expression An XQuery query A function that returns a list of nodes –End result of a FOR clause: Ordered list of tuples of document nodes Each tuple is a binding for the variables in the FOR clause

XQuery Semantics (cont’d) Example (bindings): –Let FOR declare $A and $B –Bind $A to document nodes {v,w}; $B to {x,y,z} –Then FOR clause produces the following list of bindings for $A and $B: $A/v, $B/x $A/v, $B/y $A/v, $B/z $A/w, $B/x $A/w, $B/y $A/w, $B/z

XQuery Semantics (cont’d) Step 2: filter the bindings via the WHERE clause –Use each tuple binding to substitute its components for variables; retain those bindings that make WHERE true –Example: WHERE = Binding: $A/w, where w = $B/x, where x = Then = so the WHERE condition is satisfied & binding retained

XQuery Semantics (cont’d) Step 3: Construct result –For each retained tuple of bindings, instantiate the RETURN clause –This creates a fragment of the output document –Do this for each retained tuple of bindings in sequence

Grouping and Aggregation Does not use separate grouping operator –OQL does not need one either (XML data model is object-oriented and hence similarities with OQL) –Subqueries inside the RETURN clause obviate this need (like subqueries inside SELECT did so in OQL) Uses built-in aggregate functions count, avg, sum, etc. (some borrowed from XPath)

Aggregation Example Produce a list of students along with the number of courses each student took: FOR $t IN fn:doc(“transcripts.xml”)//Transcript, $s IN $t/Student LET $c := $t/CrsTaken RETURN <StudentSummary StudId = Name = TotalCourses = {fn:count(fn:distinct-values($c))} /> ORDER BY The grouping effect is achieved because $c is bound to a new set of nodes for each binding of $t

Quantification in XQuery XQuery supports explicit quantification: –SOME (  ) and EVERY (  ) Example: Find students who have taken MAT123. FOR $t IN fn:doc(“transcript.xml”)//Transcript ctINt/CrsTaken WHERE SOME $ct IN $t/CrsTaken SATISFIES = “MAT123” RETURN $t/Student

Quantification (cont’d) Retrieve all classes (from classes.xml) where each student took the class. FOR $c IN fn:doc(classes.xml)//Class LET $g := { Transcript (: Transcript records that correspond to class $c :) $t FOR $t IN fn:doc(“transcript.xml”)//Transcript t/CrsTaken WHERE = AND = $t RETURN $t } $h := { FOR $s in fn:doc(“transcript.xml”)//Transcript RETURN $s } (: all transcript records :) WHERE EVERY $tr IN $h SATISFIES $tr IN $g RETURN $c ORDER BY

XQuery: Summary FOR-LET-WHERE-RETURN = FLWR FOR/LET Clauses WHERE Clause RETURN Clause List of tuples Instance of Xquery data model