Database Management Systems

Slides:



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

Dr. Alexandra I. Cristea XPath and Namespaces.
Bottom-up Evaluation of XPath Queries Stephanie H. Li Zhiping Zou.
Spring Part III: Introduction to XPath XML Path Language.
XML, XML Schema, Xpath and XQuery Slides collated from various sources, many from Dan Suciu at Univ. of Washington.
XPath XML Path Language. Outline XML Path Language (XPath) Data Model Description Node values XPath expressions Relative expressions Simple subset of.
XPath Laks V.S. Lakshmanan UBC CPSC 534B. Overview data model recap XPath examples some advanced features summary.
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.
Agenda from now on Done: SQL, views, transactions, conceptual modeling, E/R, relational algebra. Starting: XML To do: the database engine: –Storage –Query.
QSX (LN 3)1 Query Languages for XML XPath XQuery XSLT (not being covered today!) (Slides courtesy Wenfei Fan, Univ Edinburgh and Bell Labs)
XSL Transformations Lecture 8, 07/08/02. Templates The whole element is a template The match pattern determines where this template applies Result element(s)
Managing XML and Semistructured Data Lecture 6: XPath Prof. Dan Suciu Spring 2001.
XML May 1 st, XML for Representing Data John 3634 Sue 6343 Dick 6363 John 3634 Sue 6343 Dick 6363 row name phone “John”3634“Sue”“Dick” persons.
1 Introduction to Database Systems CSE 444 Lecture 11 Xpath/XQuery April 23, 2008.
1 Lecture 11: Xpath/XQuery Friday, October 20, 2006.
Spring חלק 3: מבוא ל- XPath XML Path Language.
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.
1 Lecture 08: XML and Semistructured Data. 2 Outline XML (Section 17) –XML syntax, semistructured data –Document Type Definitions (DTDs) XPath.
1 Lecture 08: XML and Semistructured Data. 2 Outline XML (Section 17) –XML syntax, semistructured data –Document Type Definitions (DTDs) XPath.
1 Lecture 16: Querying XML Data: XPath, XQuery Friday, February 11, 2005.
Querying XML February 12 th, Querying XML Data XPath = simple navigation through the tree XQuery = the SQL of XML XSLT = recursive traversal –will.
Introduction to XPath Bun Yue Professor, CS/CIS UHCL.
SD2520 Databases using XML and JQuery
Web Data Management XPath.
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.
1/17 ITApplications XML Module Session 7: Introduction to XPath.
XSLT and XPath, by Dr. Khalil1 XSL, XSLT and XPath Dr. Awad Khalil Computer Science Department AUC.
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.
XPath Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
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.
Management of XML and Semistructured Data Lecture 5: Query Languages Wednesday, 4/1/2001.
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.
CSE 636 Data Integration Fall 2006 XML Query Languages XPath.
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.
More XML: semantics, DTDs, XPATH February 18, 2004.
XPath Presented by Kushan Athukorala. 2 Agenda XPath XPath Terminology Selecting Nodes Predicates.
1 XML Data Management XPath Principles Werner Nutt.
Session II Chapter 3 – Chapter 3 – XPath Patterns & Expressions Chapter 4 – XPath Functions Chapter 15 – XPath 2.0http://
University of Nottingham School of Computer Science & Information Technology Introduction to XML 2. XSLT Tim Brailsford.
IS432 Semi-Structured Data Lecture 4: XPath Dr. Gamal Al-Shorbagy.
XPath --XML Path Language Motivation of XPath Data Model and Data Types Node Types Location Steps Functions XPath 2.0 Additional Functionality and its.
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 Lecture 12: XML, XPath, XQuery Friday, October 24, 2003.
1 The XPath Language. 2 XPath Expressions Flexible notation for navigating around trees A basic technology that is widely used uniqueness and scope in.
XPath.
XML path expressions CSE 350 Fall 2003.
Management of XML and Semistructured Data
Lecture 11: Xpath/XQuery
{ XML Technologies } BY: DR. M’HAMED MATAOUI
חלק 3: מבוא ל- XPath XML Path Language Spring 2005.
XML Path Language Andy Clark 17 Apr 2002.
XML: Schemas, Queries Wednesday, 4/17/2002
Lecture 12: XML, XPath, XQuery
Semi-Structured data (XML Data MODEL)
Lecture 9: XML Monday, October 17, 2005.
XPath 9-May-19.
Introduction to Database Systems CSE 444 Lecture 10 XML
More XML XML schema, XPATH, XSLT
Lecture 15: Querying XML Friday, October 27, 2000.
Semi-Structured data (XML)
Lecture 11: XML and Semistructured Data
Introduction to XML IR XML Group.
Xpath October 16, 2019 ICS 541: Xpath.
XPath 7-Dec-19.
Presentation transcript:

Database Management Systems Faculty of Computer Science Technion – Israel Institute of Technology Database Management Systems Course 236363 Tutorial 11: XPath

Outline XML Document Xpath Queries Examples and exam questions Tree structure Xpath Queries Selecting descendants and attributes Functions Shortcuts Examples and exam questions

XML Document Example <bib> <book price=“55”> Root element attribute <bib> <book price=“55”> <publisher>Addison-Wesley</publisher> <author>Serge Abiteboul</author> <author> <first-name>Rick</first-name> <last-name>Hull</last-name> </author> <author>Victor Vianu</author> <title>Foundations of Databases</title> <year>1995</year> </book> <book> <!– this is a comment --> <publisher>Freeman</publisher> <author>Jeffrey D. Ullman</author> <title>Principles of Database and Knowledge Base Systems</title> <year>1998</year> </book> </bib> Text element Comment שפה לשליפת מידע ממסמכי XML שימו לב לשוני בן תכונה של אלמנט לבין תוכן של אלמנט אתם יכולים לראות פה גם הערה. פה אפשר גם לעשות שאילתא שתחזיר את ההערה.

XML Document as a Tree Root Node Root Element . . . . bib book book price=55 publisher author . . . . Addison-Wesley Serge Abiteboul

XPath Query Example /bib/book/year Result: <year>1995</year> <year>1998</year> /bib/paper/year Empty (No elements named paper) <bib> <book price=“55”> <publisher>Addison-Wesley</publisher> <author>Serge Abiteboul</author> <author> <first-name>Rick</first-name> <last-name>Hull</last-name> </author> <author>Victor Vianu</author> <title>Foundations of Databases</title> <year>1995</year> </book> <book> <!– this is a comment --> <publisher>Freeman</publisher> <author>Jeffrey D. Ullman</author> <title>Principles of Database and Knowledge Base Systems</title> <year>1998</year> </book> </bib>

Descendent or self //author Result: <bib> <book price=“55”> <publisher>Addison-Wesley</publisher> <author>Serge Abiteboul</author> <author> <first-name>Rick</first-name> <last-name>Hull</last-name> </author> <author>Victor Vianu</author> <title>Foundations of Databases</title> <year>1995</year> </book> <book> <!– this is a comment --> <publisher>Freeman</publisher> <author>Jeffrey D. Ullman</author> <title>Principles of Database and Knowledge Base Systems</title> <year>1998</year> </book> </bib> //author Result: <author>Serge Abiteboul</author> <author> <first-name>Rick</first-name> <last-name>Hull</last-name> </author> <author>Victor Vianu</author> <author>Jeffrey D. Ullman</author> /bib//first-name // : descendent or self

Selecting non-element nodes text() Returns text nodes node() Returns any node comment() Returns comment nodes What /bib/book/author/text() will return? Author names in one text node: Serge Abiteboul Victor Vianu Jeffrey D. Ullman Rick Hull does not appear because there is no text node under the author element //comment() <!– this is a comment -->

Selecting Unknown Nodes //author/* Result: <first-name>Rick</first-name> <last-name>Hull</last-name> The * selects every node element Excluding text nodes

Accessing attributes /bib/book/@price Result: “55” <publisher>Addison-Wesley</publisher> <author>Serge Abiteboul</author> <author> <first-name>Rick</first-name> <last-name>Hull</last-name> </author> <author>Victor Vianu</author> <title>Foundations of Databases</title> <year>1995</year> </book> <book> <!– this is a comment --> <publisher>Freeman</publisher> <author>Jeffrey D. Ullman</author> <title>Principles of Database and Knowledge Base Systems</title> <year>1998</year> </book> </bib> /bib/book/@price Result: “55” @* can be used to select any attribute

Operators General comparison operators: Order comparison: =,!=,>,<,>=,<= In case of comparing a sequence with a single value returns true if there is one value matching to required comparison. Order comparison: >>,<<,is Comparing the relative order of elements in the document. Not Defined for comparing sequences.

Operators a>>b returns true << will check the opposite if node a appears after node b in the document. << will check the opposite For example: //last-name << //first-name true //first-name >> //last-name false

Selecting using Boolean Expressions /bib/book/author[first-name = “Rick”] Result: <author> <first-name>Rick</first-name> <last-name>Hull</last-name> </author> <bib> <book price=“55”> <publisher>Addison-Wesley</publisher> <author>Serge Abiteboul</author> <author> <first-name>Rick</first-name> <last-name>Hull</last-name> </author> <author>Victor Vianu</author> <title>Foundations of Databases</title> <year>1995</year> </book> <book> <!– this is a comment --> <publisher>Freeman</publisher> <author>Jeffrey D. Ullman</author> <title>Principles of Database and Knowledge Base Systems</title> <year>1998</year> </book> </bib>

Selecting using Boolean Expressions //book[@price<60][publisher = "Addison-Wesley"] the semantic meaning of [..][..] – First filter by the first expression and then filter by the second. In this case it is equivalent to : //book[@price<60 and publisher = "Addison-Wesley"] Not always equivalent!! as we will see later with different Boolean expressions

Existential Boolean Expressions /bib/book/author[first-name][address[zip][city]]/last-name Result: Last names of authors having first name and address containing zip and city. [first-name] is a Boolean condition Is it possible to return authors having first name only (and not last name)? Yes. /bib/book/author[first-name][not(last-name)]

Functions The query /bib/book[2] Is equivalent to /bib/book[position() = 2] position() returns the position of the node with respect to its context node //author[last()] last() return the position of the last node in the set of nodes with respect to the context node. לשים לב, ביחס לקבוצת הייחוס!

//author[last()] Result: <bib> <book price=“55”> <publisher>Addison-Wesley</publisher> <author>Serge Abiteboul</author> <author> <first-name>Rick</first-name> <last-name>Hull</last-name> </author> <author>Victor Vianu</author> <title>Foundations of Databases</title> <year>1995</year> </book> <book> <!– this is a comment --> <publisher>Freeman</publisher> <author>Jeffrey D. Ullman</author> <title>Principles of Database and Knowledge Base Systems</title> <year>1998</year> </book> </bib>

Functions- Equivalence(?) Example Are the following queries equivalent? //author[1][2] //author[2][1]

Functions- Equivalence(?) Example //author[1] returns the first author of each book: That is, <author>Serge Abiteboul</author> <author>Jeffery D. Ullman</author> //author[1][2] does not return values Due to the fact that each of the context nodes has only one element //author[2] equivalent to //author[2][1]: <author> <first-name>Rick</first-name> <last-name>Hull</last-name> </author> In this case, the context node is different and we return the first element. מקרה ראשון: מנסים לשלוף עבור כל סדרה את השני בסדרה (כאשר לאחר הסינון הראשוני יש רק אחד בסדרה). במקרה שני: בוחרים את הבן השני מכל ספר ואז בוחרים את הראשון (אין שום שינוי).

Functions /bib//*[name()=”book”] /bib/book[count(author)>1] Equivalent to /bib//book name() return the name of the node /bib/book[count(author)>1] Return books having more than 1 author. id(“a0130353000”) id() return nodes having the given id as input

Axes AxisName Result ancestor Selects all ancestors (parent, grandparent, etc.) of the current node ancestor-or-self Selects all ancestors (parent, grandparent, etc.) of the current node and the current node itself attribute Selects all attributes of the current node child Selects all children of the current node descendant Selects all descendants (children, grandchildren, etc.) of the current node descendant-or-self Selects all descendants (children, grandchildren, etc.) of the current node and the current node itself

Axes following Selects everything in the document after the closing tag of the current node following-sibling Selects all siblings after the current node parent Selects the parent of the current node preceding Selects all nodes that appear before the current node in the document, except ancestors, attribute nodes and namespace nodes preceding-sibling Selects all siblings before the current node self Selects the current node

Shortcuts Shortcut default child:: @ attribute:: . self::node() .. parent::node() // /descendant-or-self::node()/ [number] [position() = number]

Shortcuts - Examples Shortcut /bib/book /child::bib/child::book /bib/book/@price /child::bib/child::book/ attribute::price /.//title (equivalent to //title) /self::node()/descendant-or-self::node()/child::title //author/.. /descendant-or-self::node()/ child::author/parent::node()

Equivalence Question Are the folllowing queries equivalent? //author[1] //author/.[1] No! //author/.[1] returns all authors in the document because the /. make every author node to be its own context node.

Examples //book/publisher/parent::*/author //author/descendant-or-self::node()/child::zip ⇔ //author//zip ⇔ //author/descendant::zip What will be returned in the following? //book/publisher/parent::*/author //book[author[position()<last()]] //book[count(author[1]) = count(author[1] | author[last()] ) ] 1. מחזיר לנו את הסופרים שאת הספר שכתבו יש לו Publisher. מתחילים בשורש, עוברים לספר, לpublisher , עולים לאבא ויורדים לauthor. 2. ספרים כך שיש להם יותר מauthor אחד 3. ספרים כך שמספר הauthor הראשון שווה למספר הauthor הראשון איחוד האחרון. -> ספרים שיש להם מחבר אחד או בכלל אין להם.

Examples For which books the year of publication is the most recent? //book[ not(year < //book/year) ]

Exam Question <!ELEMENT tournament (game*)> <!ELEMENT game (GID, date, player, player, move*)> <!ELEMENT player (name, country, color)> <!ELEMENT move(no, status, piece, from, to)> <!ELEMENT piece(type, color)> To simplify the display of the DTD, assume that the elements GID, date, name, country, color, no, status, from, to, type are PCDATA. Write an XPath query that finds the name of the player who moved a piece during move number 7 of game number 99. The query must find the player by comparing the color in which he plays to the color of the tool that was moved during the course of the discussion.

Exam Question - Solution Game 99: //game[GID=99] The color of move 7 in game 99: //game[GID=99]/move[no=7]/piece/color The name of the player who moved at move 7 in game 99: //game[GID=99]/player[color = ../move[no=7]/piece/color]/name