Nikos dimitrakas – IS4/2i1242/2i4042 spring 2007 1 XML Query Languages Database Systems (4th edition) Chapter 30.5, 30.3.3, 30.3.4 Articles & Excerpts.

Slides:



Advertisements
Similar presentations
Advanced XSLT. Branching in XSLT XSLT is functional programming –The program evaluates a function –The function transforms one structure into another.
Advertisements

XML Data Management 8. XQuery Werner Nutt. Requirements for an XML Query Language David Maier, W3C XML Query Requirements: Closedness: output must be.
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 !
UFCE8V-20-3 Information Systems Development 3 (SHAPE HK) Lecture 12 Extensible Stylesheet Language Transformations : XSLT.
XML, XML Schema, Xpath and XQuery Slides collated from various sources, many from Dan Suciu at Univ. of Washington.
CSE 6331 © Leonidas Fegaras XML and Relational Databases 1 XML and Relational Databases Leonidas Fegaras.
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?
Paper by: A. Balmin, T. Eliaz, J. Hornibrook, L. Lim, G. M. Lohman, D. Simmen, M. Wang, C. Zhang Slides and Presentation By: Justin Weaver.
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.
XSL Concepts Lecture 7. XML Display Options What can XSL Transformations do? generation of constant text suppression of content moving text (e.g., exchanging.
A note on generating text with the xsl:value-of instruction.
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.
XML and DB2 By Josephine Cheng, Jane Xu IBM Santa Teresa Laboratory Slides edited from the original slides of Yunyu Song.
XML –Query Languages, Extracting from Relational Databases ADVANCED DATABASES Khawaja Mohiuddin Assistant Professor Department of Computer Sciences Bahria.
1 XQuery Values FLWR Expressions Other Expressions.
Processing of structured documents Spring 2003, Part 8 Helena Ahonen-Myka.
Overview of XPath Author: Dan McCreary Date: October, 2008 Version: 0.2 with TEI Examples M D.
Introduction to XPath Bun Yue Professor, CS/CIS UHCL.
XMLII XSchema XSchema XQuery XQuery. XML Schema XML Schema is a more sophisticated schema language which addresses the drawbacks of DTDs. Supports XML.
2.2 SQL Server 2005 的 XML 支援功能. Overview XML Enhancements in SQL Server 2005 The xml Data Type Using XQuery.
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.
TDDD43 XML and RDF Slides based on slides by Lena Strömbäck and Fang Wei-Kleiner 1.
XML Processing Moves Forward XSLT 2.0 and XQuery 1.0 Michael Kay Prague 2005.
Comparing XSLT and XQuery Michael Kay XTech 2005.
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.
Extensible Markup and Beyond
Sofia, Bulgaria | 9-10 October Using XQuery to Query and Manipulate XML Data Stephen Forte CTO, Corzen Inc Microsoft Regional Director NY/NJ (USA) Stephen.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
Lecture 22 XML querying. 2 Example 31.5 – XQuery FLWOR Expressions ‘=’ operator is a general comparison operator. XQuery also defines value comparison.
Processing of structured documents Spring 2003, Part 7 Helena Ahonen-Myka.
XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000.
JSTL, XML and XSLT An introduction to JSP Standard Tag Library and XML/XSLT transformation for Web layout.
XSLT part of XSL (Extensible Stylesheet Language) –includes also XPath and XSL Formatting Objects used to transform an XML document into: –another XML.
Computing & Information Sciences Kansas State University Thursday, 15 Mar 2007CIS 560: Database System Concepts Lecture 24 of 42 Thursday, 15 March 2007.
5/24/01 Leveraging SQL Server 2000 in ColdFusion Applications December 9, 2003 Chris Lomvardias SRA International
Database Systems Part VII: XML Querying Software School of Hunan University
Copyright© 2005 Oracle Corp.1 SQL/XML Jim Melton USA: Oracle Corp. JTC1 SC32N1632.
[ Part III of The XML seminar ] Presenter: Xiaogeng Zhao A Introduction of XQL.
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.
XP New Perspectives on XML, 2 nd Edition Tutorial 8 1 TUTORIAL 8 CREATING ELEMENT GROUPS.
XML and Database.
CS 157B: Database Management Systems II February 11 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
1 XML Data Management XPath Principles Werner Nutt.
XML Query: xQuery Reference: Xquery By Priscilla Walmsley, Published by O’Reilly.
More XML XPATH, XSLT CS 431 – February 23, 2005 Carl Lagoze – Cornell University.
©Silberschatz, Korth and Sudarshan10.1Database System Concepts XML Query Languages Notes Based on Chapter 10 of Database System Concepts.
Session II Chapter 3 – Chapter 3 – XPath Patterns & Expressions Chapter 4 – XPath Functions Chapter 15 – XPath 2.0http://
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
CSE3201/CSE4500 XPath. 2 XPath A locator for items in XML document. XPath expression gives direction of navigation.
XPath --XML Path Language Motivation of XPath Data Model and Data Types Node Types Location Steps Functions XPath 2.0 Additional Functionality and its.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
CSE 6331 © Leonidas Fegaras XQuery 1 XQuery Leonidas Fegaras.
Oracle & SQL. Oracle Data Types Character Data Types: Char(2) Varchar (20) Clob: large character string as long as 4GB Bolb and bfile: large amount of.
5 Copyright © 2004, Oracle. All rights reserved. Navigating XML Documents by Using XPath.
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
XML: Extensible Markup Language
Querying and Transforming XML Data
Session IV Chapter 16 – XQuery
{ XML Technologies } BY: DR. M’HAMED MATAOUI
XQuery Leonidas Fegaras.
More XML XML schema, XPATH, XSLT
Session II Chapter 16 – XQuery
Presentation transcript:

nikos dimitrakas – IS4/2i1242/2i4042 spring XML Query Languages Database Systems (4th edition) Chapter 30.5, , Articles & Excerpts XML Query Languages * 2 XQuery Computer Environment Tutorials DB2 & XML Querying XML Data with XQuery

nikos dimitrakas – IS4/2i1242/2i4042 spring XML Query Languages Languages for querying data stored inside XML structures XPath XSLT XQuery XML/SQL (SQL 2003c) Proprietary languages (IBM, Oracle, etc.) …

nikos dimitrakas – IS4/2i1242/2i4042 spring XPath Path expressions for navigating through XML structures Possible to set conditions and use wildcards Also includes many functions Example:

nikos dimitrakas – IS4/2i1242/2i4042 spring XSLT Enables transformations between different XML structures (mostly used for XML to HTML transformations) Example: a b

nikos dimitrakas – IS4/2i1242/2i4042 spring XQuery Query language for XML Combines XPath and FLWOR expressions –FLWOR: For Let Where Order by Return Supports use of all the functions included in XPath Inspired by many other languages like SQL, OQL, Lorel, etc.

nikos dimitrakas – IS4/2i1242/2i4042 spring XML/SQL SQL 2003 (ISO standard) –Support for XML in “relational” databases Storage Querying through XQuery –Support for constructing XML from relational data with SQL

nikos dimitrakas – IS4/2i1242/2i4042 spring Proprietary Languages Support for XML data and transformations between XML and relational data. IBM: –SQL UDFs: Extract-functions, Update-function –Mapping schemes: DAD-files Oracle: –SQL UDFs: Extract-functions, existsNode, etc. Others

nikos dimitrakas – IS4/2i1242/2i4042 spring Example This test is about the effects of computer games on the human brain Choose the computer games to be used for the test Age of Empires Flight Simulator Tetris Let users try the computer games Many users find Flight Simulator hard due to 3D environment and multiple controls Try to get funding from EU Present the results of the test

nikos dimitrakas – IS4/2i1242/2i4042 spring XPath / /elementX//elementY Wildcards * nodes() Predicates: [predicate]: –/element[1] and.. (current node and parent node) | (concatenation)

nikos dimitrakas – IS4/2i1242/2i4042 spring XPath Examples Any Results node: –//Results Any Phase that is cancelled The Date of a Phase that has a Results The Results of the Phase with Index 2 or 3 |

nikos dimitrakas – IS4/2i1242/2i4042 spring XPath Axes child, ancestor, descendant, parent –/Test/child::Phase (equivalent to /Test/Phase) –//Results/ancestor::Test

nikos dimitrakas – IS4/2i1242/2i4042 spring XQuery For –Loop through a list/set of nodes/values Let –Assignments Where –Conditions Order By –Sort the result Return –Construct an output structure

nikos dimitrakas – IS4/2i1242/2i4042 spring XQuery FLWOR expressions can be nested. No clause is compulsory. XPath expressions can be used in any clause The result can be a valid XML structure, but it doesn’t have to be. The function doc() can be used to define the input (XML source), or the execution environment can define an input context.

nikos dimitrakas – IS4/2i1242/2i4042 spring XQuery Variables start with $: –for $a in //Book/Author –let $n := Sets: –for $x in (1, 2, 3) –let $y := (1, 2, 3) Evaluating expressions: –Enclose the expression in { }: – {$x*3}

nikos dimitrakas – IS4/2i1242/2i4042 spring XQuery – Multiple results One result per value in the loop created by the for clause: for $x in (1,2,3) return {$x} Place the result in a new result: { for $x in (1,2,3) return {$x} }

nikos dimitrakas – IS4/2i1242/2i4042 spring XQuery/XPath functions Sequence functions: –distinct-values(s) –min(s), max(s), sum(s), avg(s) –empty(s), exists(s) –union(s1,s2), instersect(s1,s2), except(s1,s2) –concat(s1,s2) Node functions: –name(n), local-name(n), node-name(n)

nikos dimitrakas – IS4/2i1242/2i4042 spring XQuery/XPath functions String functions: –matches(s, regexp) –concat(s1,s2) –starts-with(s1,s2), ends-with(s1,s2), contains(s1,s2) –substring(s, start), substring(s, start, length) –lower-case(s), upper-case(s) –replace(s, pattern, replacement) –tokenize(s, pattern)

nikos dimitrakas – IS4/2i1242/2i4042 spring XQuery/XPath functions Other functions: –doc(URI) –not(e) –several date/time functions –several numeric functions –data(ns) – Sequence of nodes to sequence of atomic values –number(n) – The value of a node as a number or NaN –string(n) – The value of the node as a string –current-time(), current-date(), current-dateTime()

nikos dimitrakas – IS4/2i1242/2i4042 spring XQuery/XPath operators +, -, *, div, mod =, !=, >, = eq, ne, lt, le, gt, ge or, and, not is, >>, <<

nikos dimitrakas – IS4/2i1242/2i4042 spring XQuery functions element() –/element() (similar to /*) attribute() –/Test/attribute() (similar to node() (follows the standard??) –/node() – element nodes and text nodes – attribute nodes

nikos dimitrakas – IS4/2i1242/2i4042 spring XQuery – Computed Constructors element –element name value: let $a := “a”, $b := 2 return {element {$a} {$b}} attribute –attribute name value: let $a := “a”, $b := 2 return {attribute {$a} {$b}}

nikos dimitrakas – IS4/2i1242/2i4042 spring XQuery – Conditionals if-then-else for $a in (1 to 5) return if ($a mod 2 = 0) then {$a} else {$a}

nikos dimitrakas – IS4/2i1242/2i4042 spring XQuery – Quantifiers some for $a in /Test where some $b in satisfies string($b) = "finished" return $a/Description every for $a in /Test where every $b in satisfies string($b) = "finished" return $a/Description

nikos dimitrakas – IS4/2i1242/2i4042 spring XQuery – Nesting One result becomes the source of another expression: for $x in distinct-values (for $a in (1 to 5), $b in (1 to 5) return {$a + $b} ) return {$x}

nikos dimitrakas – IS4/2i1242/2i4042 spring XML/SQL Functions for generating XML documents as SQL results: –XMLELEMENT –XMLFOREST –XMLATTRIBUTES –XMLAGG –XMLCONCAT

nikos dimitrakas – IS4/2i1242/2i4042 spring Example table structure and data

nikos dimitrakas – IS4/2i1242/2i4042 spring XMLELEMENT Creates an XML element with a specified name and content: SELECT XMLELEMENT(NAME "Person", name) FROM Person John Higgins Steven Hendry Mathew Stevens Ken Doherty Steve Davis Paul Hunter Ronnie O'Sullivan (1 result row per element) DB2: SELECT xml2clob(XMLELEMENT(NAME "Person", name)) FROM Person

nikos dimitrakas – IS4/2i1242/2i4042 spring XMLATTRIBUTES Creates an XML attributes to be placed inside an XML element: SELECT XMLELEMENT(NAME "Person", XMLATTRIBUTES(yearofbirth), name) FROM Person John Higgins Steven Hendry Mathew Stevens Ken Doherty Steve Davis Paul Hunter Ronnie O'Sullivan

nikos dimitrakas – IS4/2i1242/2i4042 spring XMLATTRIBUTES SELECT XMLELEMENT(NAME "Person", XMLATTRIBUTES(yearofbirth AS "Year"), name) FROM Person John Higgins Steven Hendry Mathew Stevens Ken Doherty Steve Davis Paul Hunter Ronnie O'Sullivan

nikos dimitrakas – IS4/2i1242/2i4042 spring XMLATTRIBUTES SELECT XMLELEMENT(NAME "Person", XMLATTRIBUTES(yearofbirth AS "Year", name)) FROM Person

nikos dimitrakas – IS4/2i1242/2i4042 spring XMLCONCAT Combine more elements as a sequence of element. This would give us two columns: SELECT XMLELEMENT(NAME "Name", name), XMLELEMENT(NAME "Year", yearofbirth) FROM Person This would give us one column in the result: SELECT XMLCONCAT(XMLELEMENT(NAME "Name", name), XMLELEMENT(NAME "Year", yearofbirth)) FROM Person

nikos dimitrakas – IS4/2i1242/2i4042 spring XMLCONCAT John Higgins 1975 Steven Hendry 1973 Mathew Stevens 1982 Ken Doherty 1974 Steve Davis 1960 Paul Hunter 1983 Ronnie O'Sullivan 1980 Still multiple rows though

nikos dimitrakas – IS4/2i1242/2i4042 spring XMLFOREST Create multiple elements: SELECT XMLFOREST(name AS "Name", yearofbirth AS "Year") FROM Person John Higgins 1975 Steven Hendry 1973 Mathew Stevens 1982 Ken Doherty 1974 Steve Davis 1960 Paul Hunter 1983 Ronnie O'Sullivan 1980

nikos dimitrakas – IS4/2i1242/2i4042 spring Combinations Or make this more complete by combining different functions: SELECT XMLELEMENT(NAME "Person", XMLATTRIBUTES(pid AS "ID"), XMLFOREST(name AS "Name", yearofbirth AS "Year")) FROM Person John Higgins 1975 Steven Hendry 1973 Mathew Stevens 1982 Ken Doherty 1974 Steve Davis 1960 Paul Hunter 1983 Ronnie O'Sullivan 1980

nikos dimitrakas – IS4/2i1242/2i4042 spring XMLAGG Grouping many rows into one result. Can be used together with a GROUP BY clause. Put all the persons in one result row: SELECT XMLAGG(XMLELEMENT(NAME "Person", name)) FROM Person John Higgins Steven Hendry Mathew Stevens Ken Doherty Steve Davis Paul Hunter Ronnie O'Sullivan One result row! (though not well-formed XML)

nikos dimitrakas – IS4/2i1242/2i4042 spring Combinations Put all the persons in one Persons element: SELECT XMLELEMENT(NAME "Persons", XMLAGG(XMLELEMENT(NAME "Person", name))) FROM Person John Higgins Steven Hendry Mathew Stevens Ken Doherty Steve Davis Paul Hunter Ronnie O'Sullivan One result row! (AND well-formed XML)

nikos dimitrakas – IS4/2i1242/2i4042 spring XMLAGG with GROUP BY One row per group: SELECT XMLELEMENT(NAME "Color", XMLATTRIBUTES(color), XMLAGG(XMLELEMENT(NAME "Car", licencenumber))) FROM Car GROUP BY color ABC123 TYD226 RSQ199 CCD457 ROO197 DKL998 WID387 PTF357

nikos dimitrakas – IS4/2i1242/2i4042 spring Aggregates without XMLAGG SELECT XMLELEMENT(NAME "Color", XMLATTRIBUTES(color, COUNT(*) as "Amount")) FROM Car GROUP BY color

nikos dimitrakas – IS4/2i1242/2i4042 spring DB2's extra XML support Store XML documents Query data inside the XML structures Change data inside the XML structures Validate XML documents against DTDs Decompose XML documents into tables

nikos dimitrakas – IS4/2i1242/2i4042 spring Query XML data Path expressions –simple version of XPath extract-functions –two functions for each data type 1 singleton function, e.g. extractInteger 1 plural function, e.g. extractIntegers

nikos dimitrakas – IS4/2i1242/2i4042 spring Update XML data Path expressions –simple version of XPath update-function –replaces a specified path with a new value –returns the entire XML document

nikos dimitrakas – IS4/2i1242/2i4042 spring More Information XPath – XQuery – – XML/SQL – linsql.html –