Database Systems Part VII: XML Querying Software School of Hunan University 2006.10.

Slides:



Advertisements
Similar presentations
2/10/05Salman Azhar: Database Systems1 XML Query Languages Salman Azhar XPATH XQUERY These slides use some figures, definitions, and explanations from.
Advertisements

Querying on the Web: XQuery, RDQL, SparQL Semantic Web - Spring 2006 Computer Engineering Department Sharif University of Technology.
XML: Extensible Markup Language
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 !
XML, XML Schema, Xpath and XQuery Slides collated from various sources, many from Dan Suciu at Univ. of Washington.
XQuery Or, what about REAL databases?. XQuery - its place in the XML team XLink XSLT XQuery XPath XPointer.
XPath Eugenia Fernandez IUPUI. XML Path Language (XPath) a data model for representing an XML document as an abstract node tree a mechanism for addressing.
From Semistructured Data to XML: Migrating The Lore Data Model and Query Language Roy Goldman, Jason McHugh, Jennifer Widom Stanford University
1 XPath Path Expressions Conditions. 2 Paths in XML Documents uXPath is a language for describing paths in XML documents. uReally think of the semistructured.
A Graphical Environment to Query XML Data with XQuery
Query Languages Aswin Yedlapalli. XML Query data model Document is viewed as a labeled tree with nodes Successors of node may be : - an ordered sequence.
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.
Storing and Querying Ordered XML Using a Relational Database System By Khang Nguyen Based on the paper of Igor Tatarinov and Statis Viglas.
Lecture 12. Default Processing in XSLT The default processing in XSLT is to process the XPath root node The default processing for various node types.
XPath Tao Wan March 04, What is XPath? n A language designed to be used by XSL Transformations (XSLT), Xlink, Xpointer and XML Query. n Primary.
XML –Query Languages, Extracting from Relational Databases ADVANCED DATABASES Khawaja Mohiuddin Assistant Professor Department of Computer Sciences Bahria.
1 XML Query Languages XPATH XQUERY. 2 XPATH and XQUERY uXPATH is a language for describing paths in XML documents. wReally think of the semistructured.
XML, XML Schema, XPath and XQuery Query Languages CS561 Slides collated from several sources, including D. Suciu at Univ. of Washington.
Querying XML February 12 th, Querying XML Data XPath = simple navigation through the tree XQuery = the SQL of XML XSLT = recursive traversal –will.
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.
SD2520 Databases using XML and JQuery
Database Systems Part VII: XML
Lecture 7 of Advanced Databases XML Querying & Transformation Instructor: Mr.Ahmed Al Astal.
CSE3201/CSE4500 XPath. 2 XPath A locator for elements or attributes in an XML document. XPath expression gives direction.
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.
XML-QL A Query Language for XML Charuta Nakhe
TDDD43 XML and RDF Slides based on slides by Lena Strömbäck and Fang Wei-Kleiner 1.
1/17 ITApplications XML Module Session 7: Introduction to XPath.
Introduction to XPath Web Engineering, SS 2007 Tomáš Pitner.
CSE3201/CSE4500 Information Retrieval Systems
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.
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.
Processing of structured documents Spring 2003, Part 7 Helena Ahonen-Myka.
XPath. Why XPath? Common syntax, semantics for [XSLT] [XPointer][XSLT] [XPointer] Used to address parts of an XML document Provides basic facilities for.
Winter 2006Keller, Ullman, Cushing18–1 Plan 1.Information integration: important new application that motivates what follows. 2.Semistructured data: a.
August Chapter 6 - XPath & XPointer Learning XML by Erik T. Ray Slides were developed by Jack Davis College of Information Science and Technology.
Lecture 6: XML Query Languages Thursday, January 18, 2001.
XPath Aug ’10 – Dec ‘10. XPath   XML Path Language   Technology that allows to select a part or parts of an XML document to process   XPath was.
5/2/20051 XML Data Management Yaw-Huei Chen Department of Computer Science and Information Engineering National Chiayi University.
XML Name: Niki Sardjono Class: CS 157A Instructor : Prof. S. M. Lee.
WPI, MOHAMED ELTABAKH PROCESSING AND QUERYING XML 1.
[ 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.
The Semistructured-Data Model Programming Languages for XML Spring 2011 Instructor: Hassan Khosravi.
1 XML Data Management XPath Principles Werner Nutt.
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.
More XML XPATH, XSLT CS 431 – February 23, 2005 Carl Lagoze – Cornell University.
XML Query Languages XPATH XQUERY Zaki Malik November 11, 2008.
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.
CSE 6331 © Leonidas Fegaras XQuery 1 XQuery Leonidas Fegaras.
Lecture 17: XPath and XQuery Wednesday, Nov. 7, 2001.
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.
XQUERY The contents of this slide are obtained from various sources including, Wikipedia, W3School, Stanford website etc. January 2011 Dr.Kwanchai Eurviriyanukul.
Rendering XML Documents ©NIITeXtensible Markup Language/Lesson 5/Slide 1 of 46 Objectives In this session, you will learn to: * Define rendering * Identify.
XML Query languages--XPath. Objectives Understand XPath, and be able to use XPath expressions to find fragments of an XML document Understand tree patterns,
XML: Extensible Markup Language
Querying and Transforming XML Data
CS 480: Database Systems Lecture 28 March 22, 2013.
{ XML Technologies } BY: DR. M’HAMED MATAOUI
XQuery Leonidas Fegaras.
More XML XML schema, XPATH, XSLT
Presentation transcript:

Database Systems Part VII: XML Querying Software School of Hunan University

Querying XML There are several proposed query languages for XML. We will look at the two standards being proposed by the W3C: XPath and XQuery. XPath allows you to specify path expressions to navigate the tree-structured XML document. XQuery is a full query language that uses XPath for path expressions.

Example DTD <!DOCTYPE Depts [ ]>

Example XML Document Management R. Davis J. Jones Consulting L. Chu A. Lee

Path Descriptions in XPath XPath provides the ability to navigate through a document using path descriptors. Path descriptors are sequences of tags separated by slashes /.  If the descriptor begins with /, then the path starts at the root.  If the descriptor begins with //, then the path can start anywhere.  You may also start the path by giving the document name such as document(depts.xml)/. A path descriptor denotes a sequence of nodes. These nodes may themselves contain other nodes (elements). Examples:  /Depts/Dept/name  //Dept/name  document(depts.xml)/Depts/Dept/Emp/name

Path: /Depts/Dept/name Management R. Davis J. Jones Consulting L. Chu A. Lee

Path: /Depts/Dept/name (tree view) &1 &2 &3 &5 &4 &6 &9&8 &10 &7 &14 &12 &16 &18 depts Unique node identifier D1D2 @dnobudget R. Davis J. Jones L. Chu A. Lee $350,000 dept name management &11 E8 &10 name consulting E3 E6

Path: //Dept/name Management R. Davis J. Jones Consulting L. Chu A. Lee Path query returns same answer as previous one.

Path: //name Management R. Davis J. Jones Consulting L. Chu A. Lee Matches any name tag starting from anywhere in the document.

Path: /Depts/Dept Management R. Davis J. Jones Consulting L. Chu A. Lee

Wild Card Operator The "*" wild card operator can be used to denote any single tag. Examples: /*/*/name - Match any name that is nested 3 levels deep //* - Match anything

Path: /*/*/name Same as /Depts/Dept/name Management R. Davis J. Jones Consulting L. Chu A. Lee Same as /Depts/Dept/name

Question: What is /*/*/* ? Management R. Davis J. Jones Consulting L. Chu A. Lee

Attributes Attributes are referenced by putting a in front of their name. Attributes of a tag may appear in paths as if they were nested within that tag. Examples:  - dno attribute of Dept element  - eno attribute of Emp element

Path: Management R. Davis J. Jones Consulting L. Chu A. Lee

Question: What is ? Management R. Davis J. Jones Consulting L. Chu A. Lee

Predicate Expressions The set of objects returned can be filtered by putting selection conditions on the path. A predicate expression may be specified inside square brackets [..] following a tag. Only paths that have that tag and also satisfy the condition are included in the result of a path expression. Examples:  /Depts/Dept/name[name="Management"]  //Depts/Dept/budget[budget>250000] 

/ /Depts/Dept/budget[budget>250000] Management R. Davis J. Jones Consulting L. Chu A. Lee Note no budget element in first Dept so does not match path.

Axes Path expressions allow us to start at the root and execute a sequence of steps to find a set of nodes at each step. So far, we were always starting at a context node, and traversing edges to children nodes. However, XPath defines several different axes that allow us to go from the current node to other nodes. An axis specifies the tree relationship between the nodes selected by the location step and the current node. There are multiple different axes such as parent::, child::, ancestor::, and descendant:: among others. All these define a set of nodes with the given relationship with the current node.

XPath and Axes Thus, evaluating an XPath expression amounts to starting with current nodes (called context nodes) and then moving through the node hierarchy in a particular direction called an axis. XPath evaluation description:  When evaluating a path expression, the nodes selected in each step become the context nodes for the following step.  If the input to a step is several context nodes, each is evaluated in turn. Evaluating a step involves:  Enumerating( 列举 ) outgoing edges with matching labels AND  Only keeping destination nodes if they satisfy any predicate expression  The result is output in the order of evaluation.

Axes and Abbreviations An axis to traverse is specified by putting the axis name before the tag name to be matched such as child::Dept. Since this often results in long queries, some common axes have abbreviations:  The default axis is child:: which contains all children of a context node. Since it is the default, the child axis does not have to be explicitly specified.  Thus, /Depts/Dept is shorthand( 速记 ) for /Depts/child::Dept is a shorthand for the attribute:: axis.  is short for /Depts/Dept/attribute::dno .. is short for the parent:: axis. . is short for the self:: axis (current node).  // is short for descendant-or-self:: axis  // matches any node or any of its descendants

Summary of XPath Constructs Symbol Usage / Root element or separator between path steps * Match any single element Match attribute X of current element // Match any descendant (or self) of current element [C] Evaluate condition on current element [N] Picks the Nth matching element parent:: Matches parent element descendant:: Matches descendant elements self:: Matches the current element ancestor:: Matches ancestor elements child:: Matches children elements node() Matches any node (regardless of label)

DTD for Questions <!DOCTYPE Bookstore [ ]

Example XML Document for Questions Database Systems Thomas Connolly Carolyn Begg Database Systems: The Complete Book Hector Garcia- Molina Jeffrey Ullman Jennifer Widom Amazon.com says: Buy these books together for a great deal!

XPath Questions What are the elements selected by these XPath queries:  /BookStore/*/Title  //First_Name[First_Name="Thomas"]  //Last_Name[Last_Name="Ullman"]/parent::node()/  < "$60"] Write XPath queries to retrieve:  all book titles  all books < $70  all last names anywhere  all books containing a remark  all book titles where the book < $70 and Ullman is an author  retrieve the second book

XQuery XQuery allows us to query XML documents, using path expressions from XPath to describe important sets. XQuery uses FLWR expressions (“for-let-where-return") which are similar to SQL. FLWR expressions consist of:  One or more FOR and/or LET clauses (bind variables)  FOR clause iterates through bound variables, while LET store the entire sequence.  An optional WHERE clause (filters bound tuples)  Evaluated for each set of bound variables (tuple )  A RETURN clause (generates output)  Executed once for each set of bound variables (tuple) Variables begin with a dollar sign "$".

XQuery FOR Clause Example FOR $ename IN /Depts/Dept/Emp/name RETURN {$ename} Result: R. Davis J. Jones L. Chu A. Lee FOR loop variable XPath expression to retrieve sequence of nodes to iterate over Brackets used to denote not regular text

XQuery LET Clause Example LET $en IN /Depts/Dept/Emp/name RETURN {$en} Result: R. Davis, J.Jones, L. Chu, A. Lee

XQuery WHERE Clause Example FOR $e IN /Depts/Dept/Emp WHERE $e/name > “I" RETURN {$e} Result: R. Davis J. Jones L. Chu

XQuery FOR/LET Clause Example Return all departments with at least 2 employees. FOR $d IN /Depts/Dept/ LET $e = $d/Emp WHERE COUNT($e) >= 2 RETURN {$d/name} Result: Management Consulting

XQuery and IDREFs Unlike XPath, XQuery allows us to follow IDREF attributes when constructing queries. For example, if X is an IDREF attribute and Y is an ID attribute, then X => Y says go from X to the element that contains Y as an ID attribute.

XQuery IDREF Example Print the manager name for each department. FOR $d IN /Depts/Dept/ LET $en = => Emp/name RETURN {$d/name} {$en} Result: Consulting R. Davis

XQuery Questions Write XQuery queries to retrieve: 1) Return the book ISBN and price for each book. 2) Return only those books that have more than 2 authors. 3) Return average price of all books. 4) All titles of books costing < $70 where "Ullman" is an author.

Conclusion XPath is a language for specifying paths through XML documents. An XPath expression enumerates a sequence of nodes. XQuery is a full query language based on XPath. The basis of XQueries is the FLWR expression.  XPath is used to enumerate sequences of nodes.  FOR is used to iterate through nodes, LET to store the entire sequence.  WHERE is used to filter bindings and the RESULT clause specifies the output result. XPath and XQuery are still evolving standards defined by the W3C.

Objectives  Given an XML document and query description, write an Xpath query to retrieve the appropriate node sequence to answer the query.  Given an XML document and an XPath expression, list the result of evaluating the expression.  Be able to write simple XQuery queries given English text descriptions.