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.

Slides:



Advertisements
Similar presentations
Dr. Alexandra I. Cristea CS 253: Topics in Database Systems: XPath, NameSpaces.
Advertisements

Dr. Alexandra I. Cristea CS 253: Topics in Database Systems: XQuery.
XML Data Management 8. XQuery Werner Nutt. Requirements for an XML Query Language David Maier, W3C XML Query Requirements: Closedness: output must be.
Querying on the Web: XQuery, RDQL, SparQL Semantic Web - Spring 2006 Computer Engineering Department Sharif University of Technology.
IF statement (i) Single statement. IF ( logical expression ) statement Example: read(*,*) a if (a. lt. 0) a = -a write(*,*) a Or read(*,*) a if (a < 0)
XML, XML Schema, Xpath and XQuery Slides collated from various sources, many from Dan Suciu at Univ. of Washington.
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?
Lecture 13. The various node tests also work on this axis: eg node() This book has descendant-or- self nodes As expected, text nodes are included in the.
1 Lecture 10 XML Wednesday, October 18, XML Outline XML (4.6, 4.7) –Syntax –Semistructured data –DTDs.
The Systems Group at ETH Zurich XML and Databases Exercise Session 3 Ghislain Fourny © Department of Computer Science | ETH Zürich.
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.
XQuery – The W3C XML Query Language Jonathan Robie, Software AG Don Chamberlin, IBM Research Daniela Florescu, INRIA.
XML QUERY LANGUAGE Prepared by Prof. Zaniolo, Hung-chih Yang, Ling-Jyh Chen Modified by Fernando Farfán.
JavaScript, Third Edition
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
1 XQuery Values FLWR Expressions Other Expressions.
1 Lecture 08: XML and Semistructured Data. 2 Outline XML (Section 17) –XML syntax, semistructured data –Document Type Definitions (DTDs) XPath.
Managing XML and Semistructured Data Lecture 2: XML Prof. Dan Suciu Spring 2001.
Advisor: Prof. Zaniolo Hung-chih Yang Ling-Jyh Chen XML Query Language.
Lecture 6 of Advanced Databases XML Schema, Querying & Transformation Instructor: Mr.Ahmed Al Astal.
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.
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.
1 Querying XML Documents. 2 Objectives How XML generalizes relational databases The XQuery language How XML may be supported in databases.
1 XPath XPath became a W3C Recommendation 16. November 1999 XPath is a language for finding information in an XML document XPath is used to navigate through.
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.
IBM Almaden Research Center © 2006 IBM Corporation On the Path to Efficient XML Queries Andrey Balmin, Kevin Beyer, Fatma Özcan IBM Almaden Research Center.
Advance Database S Week-7 Dr.Kwanchai Eurviriyanukul
Processing of structured documents Spring 2002, Part 2 Helena Ahonen-Myka.
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.
XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000.
XSLT part of XSL (Extensible Stylesheet Language) –includes also XPath and XSL Formatting Objects used to transform an XML document into: –another XML.
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.
XQuery Leah Andrews. Overview  Queries data stored in XML trees  Declarative  High-level  Functional (no side effects)  Strongly typed  Nodes 
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.
The Semistructured-Data Model Programming Languages for XML Spring 2011 Instructor: Hassan Khosravi.
An Introduction to XML and Web Technologies The XPath Language Anders Møller & Michael I. Schwartzbach  2006 Addison-Wesley.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 4 1COMP9321, 15s2, Week.
Submitted To: Ms. Poonam Saini, Asst. Prof., NITTTR Submitted By: Rohit Handa ME (Modular) CSE 2011 Batch.
XML Query: xQuery Reference: Xquery By Priscilla Walmsley, Published by O’Reilly.
Session II Chapter 3 – Chapter 3 – XPath Patterns & Expressions Chapter 4 – XPath Functions Chapter 15 – XPath 2.0http://
Friday, September 4 th, 2009 The Systems Group at ETH Zurich XML and Databases Exercise Session 5 courtesy of Ghislain Fourny/ETH © Department of Computer.
XPath --XML Path Language Motivation of XPath Data Model and Data Types Node Types Location Steps Functions XPath 2.0 Additional Functionality and its.
Chapter 14 JavaScript: Part II The Web Warrior Guide to Web Design Technologies.
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.
Lecture 23 XQuery 1.0 and XPath 2.0 Data Model. 2 Example 31.7 – User-Defined Function Function to return staff at a given branch. DEFINE FUNCTION staffAtBranch($bNo)
1 XPath. 2 Agenda XPath Introduction XPath Nodes XPath Syntax XPath Operators XPath Q&A.
1 The XPath Language. 2 XPath Expressions Flexible notation for navigating around trees A basic technology that is widely used uniqueness and scope in.
XML Schema – XSLT Week 8 Web site:
Query Languages for XML
Session IV Chapter 16 – XQuery
Querying XML XQuery.
Querying XML XQuery.
Querying XML XPath.
Querying XML XPath.
2/18/2019.
XQuery Leonidas Fegaras.
The Selection Structure
Session II Chapter 16 – XQuery
INTRODUCTION to PERL PART 1.
ICS 101 Lab 3 Hossain Arif ICS Dept
XML and Databases Exercise Session 10 courtesy of Ghislain Fourny
Presentation transcript:

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 Science | ETH Zürich

Friday, September 4 th, 2009 PUL Algebra Theory Document Well- Formedness (Validation)Data ModelProcessing Previously, in XML&Databases 2 DTD XML Schema Infoset PSVI XDM All of this should be familiar to you by now. All of this should be familiar to you by now. XML with/without namespaces

Friday, September 4 th, 2009 PUL Algebra Theory Document Well- Formedness (Validation)Data ModelProcessing Previously, in XML&Databases 3 DTD XML Schema Infoset PSVI XDM So, now we can leverage the power of XML. XQuery XSLT XML with/without namespaces

Friday, September 4 th, 2009 PUL Algebra Theory Document Well- Formedness (Validation)Data ModelProcessing Previously, in XML&Databases 4 XML with namespaces (XML Schema) optional XDM This would be the typical setup. XQuery

Friday, September 4 th, 2009 PUL Algebra Theory Reminder: XML and Data Models 5 This is text. Physical view (syntax) Logical view (data model) a a d d This is c c b b.. text e:f

Friday, September 4 th, 2009 PUL Algebra Theory Reminder: XQuery and XPath Data Model 6 In XQuery, anything that goes into or comes out of an expression is a sequence of items! Expression for if then else where order by while any every let return exit with = +

Friday, September 4 th, 2009 PUL Algebra Theory Ever played Lego? 7

Friday, September 4 th, 2009 PUL Algebra Theory Ever played Lego? 8 if( ) then else

Friday, September 4 th, 2009 PUL Algebra Theory Ever played Lego? 9 if( ) then else my:func( )

Friday, September 4 th, 2009 PUL Algebra Theory Ever played Lego? 10 if( ) then else my:func( )

Friday, September 4 th, 2009 PUL Algebra Theory Ever played Lego? 11 if( ) then else my:func( ) 2

Friday, September 4 th, 2009 PUL Algebra Theory Ever played Lego? 12 if( ) then else for $x in let $y := return my:func( ) 2

Friday, September 4 th, 2009 PUL Algebra Theory Ever played Lego? 13 if( ) then else for $x in let $y := return my:func( ) 2

Friday, September 4 th, 2009 PUL Algebra Theory Ever played Lego? 14 if( ) then else for $x in let $y := return my:func( ) 2

Friday, September 4 th, 2009 PUL Algebra Theory Ever played Lego? 15 if( ) then else for $x in let $y := return my:func( ) 2

Friday, September 4 th, 2009 PUL Algebra Theory Ever played Lego? 16 if( ) then else for $x in let $y := return my:func( ) 2

Friday, September 4 th, 2009 PUL Algebra Theory XQuery Expressions 17 if( ) then else

Friday, September 4 th, 2009 PUL Algebra Theory XQuery Expressions 18 for $x in let $y := for $z in where order by return

Friday, September 4 th, 2009 PUL Algebra Theory XQuery Expressions 19 / / / /...

Friday, September 4 th, 2009 PUL Algebra Theory Precedence  Some expressions have priority over others while parsing an XQuery program:  Lowest priority: comma (,)  Then FLWOR, if/then/else,... on same level  Operators (+,...)  Path expressions (/)  Highest priority: literals, variables, function calls, element constructors...  Use parentheses when in doubt! 

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: Simple queries 21

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: Simple queries 22

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: Titles sorted by price 23

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: Titles sorted by price 24

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: Titles sorted by price 25

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: Titles sorted by price 26

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: How many books written by Abiteboul? 27

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: How many books written by Abiteboul? 28

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: How many books written by Abiteboul? 29

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: How many books written by Abiteboul? 30 2

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: Number of books by author 31

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: Number of books by author 32

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: Number of books by author 33

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: Number of books by author 34

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: Number of books by author 35 Stevens Abiteboul Buneman Suciu

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 1: Number of books by author 36 Stevens 2 Abiteboul 2 Buneman 1 Suciu 1

Friday, September 4 th, 2009 PUL Algebra Theory The document (from first exercise sheet) 37 You (should) know how namespaces work in XML (prefix-binding)

Friday, September 4 th, 2009 PUL Algebra Theory The document (from first exercise sheet) 38 How should we navigate a document which has namespaces with XQuery?

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: How prefixes are bound to namespaces in XQuery (Basics)  Very simple! Just a prolog declaration...  And then you can use the prefix in the XQuery code (e.g., in path expressions). 39

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: How prefixes are bound to namespaces in XQuery (Basics)  Very simple! Just a prolog declaration...  And then you can use the prefix in the XQuery code (e.g., in path expressions).  Actually, you can also bind them in element constructors just like in XML. 40

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 41

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 42

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 43

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 44

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 45

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 46

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 47

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 48

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 49

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 50

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 51

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 52

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 53

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 54

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 55

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: Let‘s try this out! 56

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 2: The other way 57

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Comparison Operators in XQuery 58

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Comparison Operators in XQuery  In XQuery, there are three kinds of comparisons  General Comparisons  Value Comparisons  Node Comparisons 59

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Comparison Operators in XQuery  In XQuery, there are three kinds of comparisons  General Comparisons =  Value Comparisons  Node Comparisons 60

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Comparison Operators in XQuery  In XQuery, there are three kinds of comparisons  General Comparisons =  Value Comparisons eq lt gt le ge  Node Comparisons 61

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Comparison Operators in XQuery  In XQuery, there are three kinds of comparisons  General Comparisons =  Value Comparisons eq lt gt le ge  Node Comparisons is 62

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: General Comparisons  To compare sequences of items  each item: atomic item or node item which is atomized 63 In XQuery, if you receive a node item where an atomic item is expected, the node is atomized. =

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: General Comparisons  To compare sequences of items  each item: atomic item or node which is atomized  Answers to the question: does any combination of  a value from the first sequence  and a value from the second sequence fulfil the condition? 64 = =

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: General Comparisons  To compare sequences of items  each item: atomic item or node which is atomized  Answers to the question: does any combination of  a value from the first sequence  and a value from the second sequence fulfil the condition? (1,2) = (3, 1 ) 65 =

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: General Comparisons  To compare sequences of items  each item: atomic item or node which is atomized  Answers to the question: does any combination of  a value from the first sequence  and a value from the second sequence fulfil the condition? (1,2) = (3, 1 ) 66 =

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: General Comparisons  To compare sequences of items  each item: atomic item or node which is atomized  Answers to the question: does any combination of  a value from the first sequence  and a value from the second sequence fulfil the condition? (1,2) = (3, 1 ) (1,2) > (3,4) 67 =

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: General Comparisons  To compare sequences of items  each item: atomic item or node which is atomized  Answers to the question: does any combination of  a value from the first sequence  and a value from the second sequence fulfil the condition? (1,2) = (3, 1 ) (1,2) > (3,4) 68 =

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Value Comparisons  Compares one value to one value (Empty sequence allowed) 69 le eq lt gt le ge

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Value Comparisons  Compares one value to one value (Empty sequence allowed) 32 eq xs:integer( 32 ) 70 eq lt gt le ge

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Value Comparisons  Compares one value to one value (Empty sequence allowed) 32 eq xs:integer( 32 ) 71 eq lt gt le ge

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Value Comparisons  Compares one value to one value (Empty sequence allowed) 32 eq xs:integer( 32 ) 31 gt xs:integer( 32 ) 72 eq lt gt le ge

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Value Comparisons  Compares one value to one value (Empty sequence allowed) 32 eq xs:integer( 32 ) 31 gt xs:integer( 32 ) 73 eq lt gt le ge

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Node Comparisons  Compares node identities 74 is

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Node Comparisons  Compares node identities let $a := let $b := $a return $a is $b 75 is

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Node Comparisons  Compares node identities let $a := let $b := $a return $a is $b 76 is

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Node Comparisons  Compares node identities let $a := let $b := $a return $a is $b let $a := let $b := return $a is $b 77 is

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Node Comparisons  Compares node identities let $a := let $b := $a return $a is $b let $a := let $b := return $a is $b 78 is

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: General/Value comparisons 79

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: General/Value comparisons  For both, values have to have comparable types (e.g., string is not comparable to integer) 80

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: General/Value comparisons  For both, values have to have comparable types (e.g., string is not comparable to integer)  Empty sequence treated differently  General comparison returns false  Value comparison returns () 81

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: General/Value comparisons  For both, values have to have comparable types (e.g., string is not comparable to integer)  Empty sequence treated differently  General comparison returns false  Value comparison returns ()  Untyped data treated differently  General comparison casts to type of other operand  Value comparison casts to string 82

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: 1=2  Find $x s.t. $x = 1 and $x = 2 83

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: 1=2  Find $x s.t. $x = 1 and $x = 2 84 (1,2)

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Transitivity of >  Find $x, $y, $z s.t. $x > $y and $y > $z and not $x > $z 85

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: Transitivity of >  Find $x, $y, $z s.t. $x > $y and $y > $z and not $x > $z 86 $x := 2 $y := (1,4) $z := 3

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: $x eq $x, $x = $x  Find $x so that both $x eq $x and $x = $x are not true. 87

Friday, September 4 th, 2009 PUL Algebra Theory Exercise 3: $x eq $x, $x = $x  Find $x so that both $x eq $x and $x = $x are not true. 88 ()

Friday, September 4 th, 2009 PUL Algebra Theory 89 Hope to see you next week!