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?

Slides:



Advertisements
Similar presentations
XML-XSL Introduction SHIJU RAJAN SHIJU RAJAN Outline Brief Overview Brief Overview What is XML? What is XML? Well Formed XML Well Formed XML Tag Name.
Advertisements

Dr. Alexandra I. Cristea CS 253: Topics in Database Systems: XPath, NameSpaces.
Dr. Alexandra I. Cristea CS 253: Topics in Database Systems: XQuery.
Dr. Alexandra I. Cristea CS 253: Topics in Database Systems: C2.
Dr. Alexandra I. Cristea XPath and Namespaces.
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.
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.
IS432: Semi-Structured Data Dr. Azeddine Chikh. 7. 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.
XML and The Relational Data Model
Processing of structured documents Spring 2003, Part 8 Helena Ahonen-Myka.
Manohar – Why XML is Required Problem: We want to save the data and retrieve it further or to transfer over the network. This.
Using XSLT and XPath to Enhance HTML Documents Reference: Roger L. Costello
XMLII XSchema XSchema XQuery XQuery. XML Schema XML Schema is a more sophisticated schema language which addresses the drawbacks of DTDs. Supports XML.
ECA 228 Internet/Intranet Design I Intro to XSL. ECA 228 Internet/Intranet Design I XSL basics W3C standards for stylesheets – CSS – XSL: Extensible Markup.
Lecture 6 of Advanced Databases XML Schema, Querying & Transformation Instructor: Mr.Ahmed Al Astal.
CG0119 Web Database Systems Using XPath to Navigate & Filter XML (via SimpleXML)‏
IS432 Semi-Structured Data Lecture 5: XSLT Dr. Gamal Al-Shorbagy.
XML TECHNOLOGY FAMILY XML XML stands for EXtensible Markup Language XML is a markup language much like HTML XML was designed to describe data[carry data],
XML DOCUMENTS & DATABASES. Summary of Introduction to XML HTML vs. XML HTML vs. XML Types of Data Types of Data Basics of XML Basics of XML XML Syntax,
XPath XPath is used to navigate through elements and attributes in an XML document. XPath is a major element in W3C's XSLT standard - and XQuery and XPointer.
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
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
WORKING WITH XSLT AND XPATH
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.
Session II Chapter 2 – Chapter 2 – XSLhttp://
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 is designed to describe data and to focus on what data is. HTML is designed to display data and to focus on how data looks.  XML is created to structure,
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.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
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.
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.
Nikos dimitrakas – IS4/2i1242/2i4042 spring XML Query Languages Database Systems (4th edition) Chapter 30.5, , Articles & Excerpts.
Unit 04 : XQuery COMP 5323 Web Database Technologies and Applications 2014.
XML and Database.
CS 157B: Database Management Systems II February 20 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron.
Submitted To: Ms. Poonam Saini, Asst. Prof., NITTTR Submitted By: Rohit Handa ME (Modular) CSE 2011 Batch.
Dr. Chunbo Chu Week 3. XML Not a replacement for HTML. XML and HTML were designed with different goals: XML was designed to transport and store data,
Unit 3 — Advanced Internet Technologies Lesson 11 — Introduction to XSL.
XML Query: xQuery Reference: Xquery By Priscilla Walmsley, Published by O’Reilly.
What is XLink? XLink is short for XML Linking Language XLink is used to create hyperlinks in XML documents Any element in an XML document can behave as.
IS432 Semi-Structured Data Lecture 6: XQuery Dr. Gamal Al-Shorbagy.
XSLT: How Do We Use It? Nancy Hallberg Nikki Massaro Kauffman.
What is it? –w3c standard for… Navigating through an XML document Filtering & finding information –Includes… Expressions for navigating to parts of an.
XML Introduction to XML Extensible Markup Language.
XML Schema – XSLT Week 8 Web site:
XQUERY The contents of this slide are obtained from various sources including, Wikipedia, W3School, Stanford website etc. January 2011 Dr.Kwanchai Eurviriyanukul.
1 XSL Transformations (XSLT). 2 XSLT XSLT is a language for transforming XML documents into XHTML documents or to other XML documents. XSLT uses XPath.
XML Notes taken from w3schools. What is XML? XML stands for EXtensible Markup Language. XML was designed to store and transport data. XML was designed.
XML. What is XML? XML stands for EXtensible Markup Language XML is a markup language much like HTML XML was designed to carry data, not to display data.
XML Query languages--XPath. Objectives Understand XPath, and be able to use XPath expressions to find fragments of an XML document Understand tree patterns,
Query Languages for XML
XML: Extensible Markup Language
Querying and Transforming XML Data
Session IV Chapter 16 – XQuery
What is XLink? What is XPointer?
{ XML Technologies } BY: DR. M’HAMED MATAOUI
Querying XML XQuery.
Querying XML XQuery.
2/18/2019.
Session II Chapter 16 – XQuery
Presentation transcript:

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? – XQuery is the language for querying XML data – XQuery for XML is like SQL for databases – XQuery is built on XPath expressions – XQuery is supported by all major databases – XQuery is a W3C Recommendation

3 XQuery - Examples of Use XQuery can be used to: –Extract information to use in a Web Service –Generate summary reports –Transform XML data to XHTML –Search Web documents for relevant information

4 How to Select Nodes From "books.xml"? Functions –XQuery uses functions to extract data from XML documents. –The doc() function is used to open the "books.xml" file: Path Expressions –XQuery uses path expressions to navigate through elements in an XML document Predicates –XQuery uses predicates to limit the extracted data from XML docs doc("books.xml") doc("books.xml")/bookstore/book/title doc("books.xml")/bookstore/book[price<30]

5 FLWOR Expressions FLWOR is an acronym for "For, Let, Where, Order by, Return" –for clause selects all book elements under the bookstore element into a variable called $x. –where clause selects only book elements with a price element with a value greater than 30. –order by clause defines the sort-order. Will be sort by the title element. –return clause specifies what should be returned. Here it returns the title elements. for $x in doc("books.xml")/bookstore/book where $x/price>30 order by $x/title return $x/title

6 FLWOR Expressions (cont) The above XQuery expression will yield the result: Which is equivalent to the path expression: doc("books.xml")/bookstore/book[price>30]/title Learning XML XQuery Kick Start

7 Present Result In HTML Adding HTML tags to generate neatly result Result { for $x in doc("books.xml")/bookstore/book/title order by $x return {$x} } Everyday Italian Harry Potter Learning XML XQuery Kick Start

8 Present Result In HTML (cont) Using data() to strip out XML tags Result Everyday Italian Harry Potter Learning XML XQuery Kick Start { for $x in doc("books.xml")/bookstore/book/title order by $x return {data($x)} }

9 XQuery Basic Syntax Rules Some basic syntax rules: –XQuery is case-sensitive –XQuery elements, attributes, and variables must be valid XML names –An XQuery string value can be in single or double quotes –An XQuery variable is defined with a $ followed by a name, e.g. $bookstore –XQuery comments are delimited by (: and :), e.g. (: XQuery Comment :)

10 XQuery Conditional Expressions "If-Then-Else" expressions are allowed in XQuery The result will be: for $x in doc("books.xml")/bookstore/book return if then {data($x/title)} else {data($x/title)} Notes on the "if-then-else" syntax: parentheses around the if expression are required. else is required, but it can be just else(). Everyday Italian Harry Potter Learning XML XQuery Kick Start

11 XQuery Comparisons In XQuery there are two ways of comparing values: 1. General comparisons: =, !=,, >= 2. Value comparisons: eq, ne, lt, le, gt, ge Difference between two comparison methods are: –The following expression returns true if any q attributes have a value greater than 10: –The following expression returns true if there is only one q attribute returned by the expression, and its value is greater than 10. If more than one q is returned, an error occurs: > 10 gt 10

12 Adding Elements Adding Elements to the result XQuery expression above will generate: { for $x in doc("books.xml")/bookstore/book order by $x/title return {data($x/title)}. Category: } Everyday Italian. Category: COOKING Harry Potter. Category: CHILDREN Learning XML. Category: WEB XQuery Kick Start. Category: WEB

13 Adding Attributes Add Attributes to HTML Elements XQuery expression above will generate: { for $x in doc("books.xml")/bookstore/book order by $x/title return {data($x/title)} } Everyday Italian Harry Potter Learning XML XQuery Kick Start

14 Selecting and Filtering for Clause –for clause binds a variable to each item returned by in expression. –for clause results in iteration. –There can be multiple for clauses in the same FLWOR expression. –To loop a specific number of times in for clause, we may use to keyword: –Result: for $x in (1 to 5) return {$x}

15 for Clause (cont) The at keyword can be used to count the iteration: Result: for $x at $i in doc("books.xml")/bookstore/book/title return {$i}. {data($x)} 1. Everyday Italian 2. Harry Potter 3. XQuery Kick Start 4. Learning XML

16 for Clause (cont) It is also allowed with more than one in expression in the for clause. Use comma to separate each in expression: Result: for $x in (10,20), $y in (100,200) return x={$x} and y={$y} x=10 and y=100 x=10 and y=200 x=20 and y=100 x=20 and y=200

17 let Clause let clause allows variable assignments It avoids repeating the same expression many times. The let clause does not result in iteration Return let $x := (1 to 5) return {$x}

18 where Clause where clause is used to specify one or more criteria for the result: Only the books with the price between 31 and 99 will be selected: where $x/price>30 and $x/price<100

19 order by Clause order by clause is used to specify the sort order of the result. The result will be sorted by category and title as: for $x in doc("books.xml")/bookstore/book order by $x/title return $x/title Harry Potter Everyday Italian Learning XML XQuery Kick Start

20 return clause return clause specifies what is to be returned. Result: for $x in doc("books.xml")/bookstore/book return $x/title Everyday Italian Harry Potter XQuery Kick Start Learning XML

21 XQuery Functions XQuery 1.0, XPath 2.0, and XSLT 2.0 share the same functions library. A call to function can appear where expression may appear 1: In an element 2: In the predicate of a path expression 3: In a let clause {uppercase($booktitle)} doc("books.xml")/bookstore/book[substring(title,1,5)='Harry'] let $name := (substring($booktitle,1,4))

22 User-Defined Functions User-defined functions can be defined in the query or in a separate library Notes on user-defined functions: –Use the declare function keyword –The name of the function must be prefixed –The data type of the parameters are mostly the same as the data types defined in XML Schema –The body of the function must be surrounded by curly braces declare function prefix:function_name($parameter as datatype, …) as returnDatatype {...function code here... } Syntax:

23 Example of User-defined Function This is an example of a User-defined Function Declared in the Query And this is an example of how to call the function above: declare function local:minPrice($p as xs:float, $d as xs:floatl) as xs:float { let $disc := ($p * $d) div 100 return ($p - $disc) } ; {local:minPrice($book/price, $book/discount)}