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.

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.
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?
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation Pivoting and SQL:1999.
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.
A Graphical Environment to Query XML Data with XQuery
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.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
XQuery – The W3C XML Query Language Jonathan Robie, Software AG Don Chamberlin, IBM Research Daniela Florescu, INRIA.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Axiomatic Semantics ICS 535.
XML QUERY LANGUAGE Prepared by Prof. Zaniolo, Hung-chih Yang, Ling-Jyh Chen Modified by Fernando Farfán.
XML –Query Languages, Extracting from Relational Databases ADVANCED DATABASES Khawaja Mohiuddin Assistant Professor Department of Computer Sciences Bahria.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements II.
1 XQuery Values FLWR Expressions Other Expressions.
Processing of structured documents Spring 2003, Part 8 Helena Ahonen-Myka.
Introduction to XPath Bun Yue Professor, CS/CIS UHCL.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation MongoDB Read Lecturer.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation MongoDB Write Lecturer.
Advisor: Prof. Zaniolo Hung-chih Yang Ling-Jyh Chen XML Query Language.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation Document Type Definition.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation XML Schema 1 Lecturer.
TDDD43 XML and RDF Slides based on slides by Lena Strömbäck and Fang Wei-Kleiner 1.
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 XML Storage Techniques.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation eXist Update Lecturer.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation XML Schema 2 Lecturer.
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.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation MongoDB Aggregation.
XSLT part of XSL (Extensible Stylesheet Language) –includes also XPath and XSL Formatting Objects used to transform an XML document into: –another XML.
CSE314 Database Systems The Relational Algebra and Relational Calculus Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
Nikos dimitrakas – IS4/2i1242/2i4042 spring XML Query Languages Database Systems (4th edition) Chapter 30.5, , Articles & Excerpts.
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.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation Identity Constraints.
Unit 04 : XQuery COMP 5323 Web Database Technologies and Applications 2014.
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 XML.
Information Management XML and Databases hussein suleman uct cs
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation Exam and Lecture Overview.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation MongoDB Architecture.
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.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
1 XML Data Management XPath Principles Werner Nutt.
XML Query: xQuery Reference: Xquery By Priscilla Walmsley, Published by O’Reilly.
XPath --XML Path Language Motivation of XPath Data Model and Data Types Node Types Location Steps Functions XPath 2.0 Additional Functionality and its.
This PowerPoint is based on slides from: Rajshekhar Sunderraman, Department of Computer Science Georgia State University.
Restrictions Objectives of the Lecture : To consider the algebraic Restrict operator; To consider the Restrict operator and its comparators in SQL.
Module 3: Using XML. Overview Retrieving XML by Using FOR XML Shredding XML by Using OPENXML Introducing XQuery Using the xml Data Type.
CSE 6331 © Leonidas Fegaras XQuery 1 XQuery Leonidas Fegaras.
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.
Query Languages for XML
CSE202 Database Management Systems
XML: Extensible Markup Language
Lecturer : Dr. Pavle Mogin
Querying and Transforming XML Data
Lecturer : Dr. Pavle Mogin
Session IV Chapter 16 – XQuery
{ XML Technologies } BY: DR. M’HAMED MATAOUI
Expressions and Control Flow in JavaScript
SQL: Structured Query Language DML- Queries Lecturer: Dr Pavle Mogin
Chapter 8 JavaScript: Control Statements, Part 2
XQuery Leonidas Fegaras.
The Selection Structure
Session II Chapter 16 – XQuery
CS 405G: Introduction to Database Systems
Presentation transcript:

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 Language 1 Lecturer : Dr. Pavle Mogin

SWEN 432 Advanced Database Design and Implementation 2015 XQuery Language 1 Plan For XML Query Languages Why XQuery? What is XQuery XQuery expressions –Arithmetic expressions, –Comparison expressions, –Logical expressions –Element constructor –FLWOR expressions –Background: Query Data Model, XPath –Redings: Ramakrisnan, Gehrke: Database Management Systems, Chapter 27, Section 7 XQuery 1.0: An XML Query Language, W3C Working Draft, 29 October 2004, XQuery 1.0 and Xpath 2.0 Functions and Operators, W3C

SWEN 432 Advanced Database Design and Implementation 2015 XQuery Language 2 Why XQuery? A number of different XML query languages like: –XPath, –Lorel, –XML-QL, and –Quilt have been developed during the last two decades A number of years ago, W3C proposed XQuery XQuery has been adopted as a native XML database query language In parallel, SQL standard committee has defined SQL/XML to extend SQL:1999

SWEN 432 Advanced Database Design and Implementation 2015 XQuery Language 3 What kind of a Query Language is XQuery XQuery is a functional language –It is composed of expressions –Expressions return results without any side effects XQuery expressions are produced by combining simpler expressions using operators and key words Key words are written using lower case letters Besides primary expressions you saw in Query Data Model (literals, variables, function calls), XQuery supports: –XPath expressions, –Arithmetic expressions, –Element constructor, –FLWOR expressions, and –Conditional expressions

SWEN 432 Advanced Database Design and Implementation 2015 XQuery Language 4 Arithmetic Expressions XQuery supports: –Common arithmetic operators +, -, *, div, mod, and –Aggregate functions like count(), sum(), avg(), min(), max() –Operator div is used instead of “ / ” Arithmetic operators are defined on numeric values Aggregate functions are defined on sequences of (numeric) values –If an operand is a node, the arithmetic operator is applied on its typed value –If an operand is an empty sequence, the operator also returns an empty sequence

SWEN 432 Advanced Database Design and Implementation 2015 XQuery Language 5 Comparison Expressions Comparison expressions allow two values to be compared XQuery provides three kinds of comparison expressions –Value comparison with operators eq, ne, lt, le, gt, ge –General comparison with operators =, !=,, >= –Node comparison with operators is, > Operands of comparison expressions are called range expressions Formally, o1θo2o1θo2 where o 1, o 2 are operands and θ is a comparison operator

SWEN 432 Advanced Database Design and Implementation 2015 XQuery Language 6 Value Comparison A value comparison is used to compare single values only –First are operands evaluated –If both operands consist of exactly one value, and value types are appropriate, the comparison is true if o 1 θo 2 evaluates true The following value comparison is true eq “s1”] only if the XPath expression returns only node and the node has a value of “s1”, otherwise XQuery will raise an error (more nodes), or return false (not “s1” ) The following value comparison returns true 5 eq 5

SWEN 432 Advanced Database Design and Implementation 2015 XQuery Language 7 General Comparison A general comparison is used to compare sequences of any length General comparisons are existentially quantified, they return true if at lest one pair of elements from both sequences satisfy the comparison operator The following general comparison evaluates true = “s1”] if the XPath expression returns at least node with a value of “s1”, otherwise XQuery will return false The following general comparison evaluates true (2, 3) = (3, 4, 5)

SWEN 432 Advanced Database Design and Implementation 2015 XQuery Language 8 Node Comparison Node comparisons are used to compare two nodes, by their identity, or by their document order Each operand has to be either a single node, or an empty sequence –If an operand is an empty sequence, the result is also an empty sequence –A comparison with the is operator returns true, if both operands have the same identifier –A comparison with << operator returns true, if the left operand has a smaller identifier value than the right operand with regard to the document order

SWEN 432 Advanced Database Design and Implementation 2015 XQuery Language 9 Logical Expressions A logical expression is: –an and-expression, –an or-expression, or –A not-expression If a logical expression does not raise an error, its value is always either true or false The following expression returns true 1 eq 1 and 2 le 3 XQuery provides a function named fn:not –The function reduces its parameter to a Boolean value –It returns true if the Boolean value of the parameter is false and vice versa –fn:not(2 < 1) = T

SWEN 432 Advanced Database Design and Implementation 2015 XQuery Language 10 Comments Comments are in XQuery placed between “ (: ” and “ :) ” Example: (:SWEN432 people enjoy doing XQuery:)

SWEN 432 Advanced Database Design and Implementation 2015 XQuery Language 11 Element Constructors XPath expressions select existing nodes XQuery queries should return new XML documents or XML fragments Element constructor expressions are used to construct new XML There are: –Direct element constructors, where element names are constants, and values can be either constants, or results of evaluating expressions, and –Computed element constructors, where even element names can be evaluated We consider the direct element constructors, only

SWEN 432 Advanced Database Design and Implementation 2015 XQuery Language 12 Direct Element Constructor A direct element constructor contains: –Start and end tags, with a content between them –The content of an element constructor may be: Text, Other element constructors, and Expressions, placed between curly braces –Expressions within curly braces are evaluated and replaced by values –The result of evaluating an expression can be any sequence of nodes and atomic values –If an expression returns a node, the node and all its descendants will be included in the content of the element constructor

SWEN 432 Advanced Database Design and Implementation 2015 XQuery Language 13 surname Query Data Model Tree of students.xml d1d1 students.xml e1e1 students e2e2 e5e5 student a1a1 t1t1 e3e3 e4e4 s1 sid James name t2t2 Bond surname t3t3 e6e6 e7e7 Roger name t4t4 Smith a2a2 s2 sid surname Emmy name Smith s3 sid a3a3 e8e8 e 10 t5t5 t6t6 e9e9

SWEN 432 Advanced Database Design and Implementation 2015 XQuery Language 14 Element Constructor Example The following is a constant only element constructor James Bond Let the variable $s be defined as for $s in fn:doc("students.xml") /students/student = "s1"  Then the following element constructor returns the above constant only element constructor  $s/name, $s/surname 

SWEN 432 Advanced Database Design and Implementation 2015 XQuery Language 15 FLWOR Expressions (1) FLWOR stands for –for, (used to iterate through the result of an XPath expression and to bind a variable in tern to each object of the result) –let, (used to bind a variable to the whole sequence of objects returned by an XPath expression) –where, (used to select those objects from the result returned by an XPath expression that satisfy given conditions) –order by, (used to sort the result of an XPath expression) and –return (used to construct the query result) FLWOR is pronounced as flower FLWOR expressions allow: –Iterating through XML documents –Binding variables to the iteration results, –Restructuring XML documents, and –Joining XML documents

SWEN 432 Advanced Database Design and Implementation 2015 XQuery Language 16 FLWOR Expressions (2) A FLWOR expression has: –At lest one for or let clause, –At most one where clause, –At most one order by clause, and –Exactly one return expression

SWEN 432 Advanced Database Design and Implementation 2015 XQuery Language 17 Return Clause and Element Constructor A return clause contains exactly one element constructor that may contain other element constructors Example 1: for $n in (1, 2) return (:Wrong! These are 2 element constructors:) Example 2: for $n in (1, 2) return (:Correct:)

SWEN 432 Advanced Database Design and Implementation 2015 XQuery Language 18 for and let Clauses for and let clauses are used to bind variables to values returned by an expression for clause is also used to iterate over a sequence of values A FLWOR expression may contain more than one for and let clause, each containing at least one variable for $n in (2, 3), $m in (5, 6) return {$n} times {$m} is {$n*$m} The query returns 2 times 5 is 10 … 3 times 6 is 18

SWEN 432 Advanced Database Design and Implementation 2015 XQuery Language 19 Difference Between for and let The for clause binds a variable to each value of a sequence, one at a time The let clause binds a variable to a whole sequence at once for $n in (1 to 3) let $m:=(1 to $n) return {$n} {$m} The query result will be:

SWEN 432 Advanced Database Design and Implementation 2015 XQuery Language 20 More About for and let Assume a query contains just one variable The return clause executes the element constructor for each binding of the variable to values for $s in fn:doc(“students.xml”)/students/student return {$s/name} Result: James … Emmy There were 3 executions of the element constructor

SWEN 432 Advanced Database Design and Implementation 2015 XQuery Language 21 More About for and let let $s:=fn:doc(“students.xml”)/students/student return {$s/name} Result: James Roger Emmy There was only 1 execution of the element constructor

SWEN 432 Advanced Database Design and Implementation 2015 XQuery Language 22 Summary (1) XQuery is a query language proposed by W3C for XML documents and native XML databases XQuery is a functional language –It is composed of expressions –Expressions return results without any side effects XQuery supports various types of expressions: –XPath expressions, –Arithmetic expressions, –Comparison expressions, –Logical expressions The element constructor is the most important concept that makes the XQuery superior to XPath The element constructor is used to construct the result of a query

SWEN 432 Advanced Database Design and Implementation 2015 XQuery Language 23 Summary (2) FLOWR expression –for –let –where –order by –return for and let closes –The for clause binds a variable to each value of a sequence, one at a time –The let clause binds a variable to a whole sequence at once