XML Query: xQuery Reference: Xquery By Priscilla Walmsley, Published by O’Reilly.

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

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?
SPARQL for Querying PML Data Jitin Arora. Overview SPARQL: Query Language for RDF Graphs W3C Recommendation since 15 January 2008 Outline: Basic Concepts.
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.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
1 COS 425: Database and Information Management Systems XML and information exchange.
XML –Query Languages, Extracting from Relational Databases ADVANCED DATABASES Khawaja Mohiuddin Assistant Professor Department of Computer Sciences Bahria.
JavaScript, Third Edition
Microsoft Access 2010 Chapter 7 Using SQL.
Processing of structured documents Spring 2003, Part 8 Helena Ahonen-Myka.
Basic Elements of C++ Chapter 2.
Introduction to XPath Bun Yue Professor, CS/CIS UHCL.
SD2520 Databases using XML and JQuery
XMLII XSchema XSchema XQuery XQuery. XML Schema XML Schema is a more sophisticated schema language which addresses the drawbacks of DTDs. Supports XML.
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.
Introduction to Databases Chapter 7: Data Access and Manipulation.
TDDD43 XML and RDF Slides based on slides by Lena Strömbäck and Fang Wei-Kleiner 1.
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.
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
WORKING WITH XSLT AND XPATH
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 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
Using the selection structure (Unit 7) Visual Basic for Applications.
Chapter 3: Data Types and Operators JavaScript - Introductory.
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.
CITA 330 Section 6 XSLT. Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "
XSLT Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
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 Exam and Lecture Overview.
Database Systems Part VII: XML Querying Software School of Hunan University
Introduction to LINQ Chapter 11. Introduction Large amounts of data are often stored in a database—an organized collection of data. A database management.
XML – Part III. The Element … This type of element either has the element content or the mixed content (child element and data) The attributes of the.
Chapter 12: String Manipulation Introduction to Programming with C++ Fourth Edition.
[ 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.
1 Tutorial 14 Validating Documents with Schemas Exploring the XML Schema Vocabulary.
Tutorial 13 Validating Documents with Schemas
JSTL The JavaServer Pages Standard Tag Library (JSTL) is a collection of useful JSP tags which encapsulates core functionality common to many JSP applications.
Programming Fundamentals. Today’s Lecture The Conditional Operator Logical Operators Structures Enumerations.
1 Typing XQuery WANG Zhen (Selina) Something about the Internship Group Name: PROTHEO, Inria, France Research: Rewriting and strategies, Constraints,
XP New Perspectives on XML, 2 nd Edition Tutorial 7 1 TUTORIAL 7 CREATING A COMPUTATIONAL STYLESHEET.
XPath --XML Path Language Motivation of XPath Data Model and Data Types Node Types Location Steps Functions XPath 2.0 Additional Functionality and its.
XP 1 XSLT II Robin Burke ECT 360. XP 2 Homework #4 Forgot we hadn't covered "choose" becomes extra credit My books.xml didn't include descriptions.
Module 3: Using XML. Overview Retrieving XML by Using FOR XML Shredding XML by Using OPENXML Introducing XQuery Using the xml Data Type.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Displaying Data with XSLT ©NIITeXtensible Markup Language/Lesson 6/Slide 1 of 45 Objectives In this lesson, you will learn to: * Perform conditional formatting.
XML Schema – XSLT Week 8 Web site:
Chapter 11.  Large amounts of data are often stored in a database—an organized collection of data.  A database management system (DBMS) provides mechanisms.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
XML: Extensible Markup Language
Chapter Topics The Basics of a C++ Program Data Types
Relational Database Design
Querying and Transforming XML Data
Basic Elements of C++.
CS 480: Database Systems Lecture 28 March 22, 2013.
{ XML Technologies } BY: DR. M’HAMED MATAOUI
Basic Elements of C++ Chapter 2.
Topics Introduction to File Input and Output
Introduction to LINQ Chapter 11 10/28/2015 Lect 4 CT1411.
WEB PROGRAMMING JavaScript.
Introduction to LINQ Chapter 11.
Session II Chapter 16 – XQuery
Presentation transcript:

XML Query: xQuery Reference: Xquery By Priscilla Walmsley, Published by O’Reilly

XQuery Enormous amount of information is now stored in XML, both in XML databases and in documents on a filesystem All of this data is used for a variety of purposes XQuery is a query language designed by the W3C to address these needs It allows you to select the XML data elements of interest, reorganize and possibly transform them, and return the results in a structure as you want

Capabilities of XQuery Selecting information based on specific criteria Filtering out unwanted information Searching for information within a document or set of documents Joining data from multiple documents or collections of documents Sorting, grouping, and aggregating data Transforming and restructuring XML data into another XML vocabulary or structure Performing arithmetic calculations on numbers and dates Manipulating strings to reformat text

Path Expressions Simply selects elements or attributes from an input document: Examples doc("catalog.xml")/catalog/product = "ACC"] doc("catalog.xml")/catalog/product[2]

Path Expressions Path expressions are convenient because of their compact, easy-to-remember syntax. However, they have a limitation: – they can only return elements and attributes as they appear in input documents. – Any elements selected in a path expression appear in the results with the same names, the same attributes and contents, – and in the same order as in the input document.

FLWORs stands for “for, let, where, order by, return” FLWORs, unlike path expressions, allow you to manipulate, transform, and sort your results. A Simple Query for $prod in doc("catalog.xml")/catalog/product where = "ACC" order by $prod/name return $prod/name

FLWORs For – This clause sets up an iteration through the product nodes, and the rest of the FLWOR is evaluated once for each of the four products. – Each time, a variable named $prod is bound to a different product element. – Dollar signs are used to indicate variable names in XQuery. for $prod in doc("catalog.xml")/catalog/product where = "ACC" order by $prod/name return $prod/name

FLWORs where – This clause selects only products in the ACC department. – This has the same effect as a predicate = "ACC"]) in a path expression. for $prod in doc("catalog.xml")/catalog/product where = "ACC" order by $prod/name return $prod/name

FLWORs order by – This clause sorts the results by product name, something that is not possible with path expressions. for $prod in doc("catalog.xml")/catalog/product where = "ACC" order by $prod/name return $prod/name

FLWORs order by – This clause sorts the results by product name, something that is not possible with path expressions. for $prod in doc("catalog.xml")/catalog/product where = "ACC" order by $prod/name return $prod/name

FLWORs return – This clause indicates that the product element’s name children should be returned. for $prod in doc("catalog.xml")/catalog/product where = "ACC" order by $prod/name return $prod/name

FLWORs The let clause (the L in FLWOR) is used to set the value of a variable – second line is a let clause that assigns the product element’s name child to a variable called $name. – The $name variable is then referenced later in the FLWOR, in both the order by clause and the return clause for $product in doc("catalog.xml")/catalog/product let $name := $product/name where = "ACC" order by $name return $name

FLWORs The let clause serves as a programmatic convenience that avoids repeating the same expression multiple times. Using some implementations, it can also improve performance, because the expression is evaluated only once instead of each time it is needed.

Wrap the results wrap the results of your query in a different XML vocabulary Query { for $product in doc("catalog.xml")/catalog/product where order by $product/name return $product/name } ……. Results Deluxe Travel Bag Floppy Sun Hat

Another Example There are {count(doc("catalog.xml")//product)} products. There are 4 products. Query: Results:

You can include element constructors at various places in your query Query: { for $product in doc("catalog.xml")/catalog/product where order by $product/name return {$product/name} } Results: Deluxe Travel Bag Floppy Sun Hat

attributes to results and data function You can also add your own attributes to results using an XML-like syntax Query { for $product in doc("catalog.xml")/catalog/product where order by $product/name return {data($product/name)} } Results Deluxe Travel Bag Floppy Sun Hat

Functions There are over 100 functions built into XQuery, covering a broad range of functionality. Functions can be used to manipulate strings and dates, perform mathematical calculations, combine sequences of elements, and perform many other useful jobs. You can also define your own functions, either in the query itself, or in an external library Both built-in and user-defined functions can be called from almost any place in a query.

Typical function call – substring($prodName, 1, 5) where the name of the function is substring and there are three arguments, separated by commas and surrounded by parentheses. The first argument is a variable reference, whereas the other two are numeric literals. XQuery comments, delimited by (: and :) – (: This query returns the children :)

Evaluation Order and Parentheses if ($x 0) then $x + $y else $x - $y if (($x 0)) then ($x + $y) else ($x - $y) any and operators are evaluated before or operators – true() and true() or false() and false( ) – (true() and true( )) or (false() and false( ))

Conditional (if-then-else) Expressions Query for $prod in (doc("catalog.xml")/catalog/product) return if = 'ACC') then {data($prod/number)} else {data($prod/number)} Results

Conditional expression returning multiple expressions Query for $prod in (doc("catalog.xml")/catalog/product) return if = 'ACC') then ( {data($prod/number)}, {data($prod/name)} ) else {data($prod/number)} Results Floppy Sun Hat 443 Deluxe Travel Bag 784

XQuery and XML Schema XQuery uses the type system of XML Schema, which includes built-in types that represent common datatypes such as decimal, date, and string. XML Schema also specifies a language for defining your own types based on the built-in types. For example, if your item element has a quantity attribute, and you know from the schema that the type of the quantity attribute is xs:integer, you can perform sorts or other operations on that attribute’s value without converting it to an integer in the query