XPath Laks V.S. Lakshmanan UBC CPSC 534B. Overview data model recap XPath examples some advanced features summary.

Slides:



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

XML: Extensible Markup Language
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.
Managing Data Exchange: XPath
XPath XML Path Language. Outline XML Path Language (XPath) Data Model Description Node values XPath expressions Relative expressions Simple subset of.
Transforming XML Part I Document Navigation with XPath John Arnett, MSc Standards Modeller Information and Statistics Division NHSScotland Tel:
The learning site: /xpath_syntax.asp xsl/xsl/slides.html.
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.
Multi Platform Applications XML, XPath, XSLT transform.
Lecture 10. Back to the table example We can now return to considering in detail the first XSLT style-sheet we saw –The one which, when applied to the.
Lecture 13. The various node tests also work on this axis: eg node() This book has descendant-or- self nodes As expected, text nodes are included in the.
Lecture 13. The various node tests also work on this axis: eg node() This book has descendant-or- self nodes As expected, text nodes are included in the.
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)
1 COS 425: Database and Information Management Systems XML and information exchange.
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.
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.
XML Language Family Detailed Examples Most information contained in these slide comes from: These slides are intended.
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.
XML, XML Schema, XPath and XQuery Query Languages CS561 Slides collated from several sources, including D. Suciu at Univ. of Washington.
Managing XML and Semistructured Data Lecture 2: XML Prof. Dan Suciu Spring 2001.
Querying XML February 12 th, Querying XML Data XPath = simple navigation through the tree XQuery = the SQL of XML XSLT = recursive traversal –will.
1 Advanced Topics XML and Databases. 2 XML u Overview u Structure of XML Data –XML Document Type Definition DTD –Namespaces –XML Schema u Query and Transformation.
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
Navigating XML. Overview  Xpath is a non-xml syntax to be used with XSLT and Xpointer. Its purpose according to the W3.org is  to address parts of an.
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.
TDDD43 XML and RDF Slides based on slides by Lena Strömbäck and Fang Wei-Kleiner 1.
Xpath Xlink Xpointer Xquery Sources:
SDPL 20075: Overview of XSLT1 5 Document Transformations n XSLT (1.0 W3C Rec. 11/1999; XSLT 2.0 Rec. 1/07) –A language for transforming XML documents –initial.
1/17 ITApplications XML Module Session 7: Introduction to XPath.
Introduction to XPath Web Engineering, SS 2007 Tomáš Pitner.
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.
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.
Database Systems Part VII: XML Querying Software School of Hunan University
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.
WPI, MOHAMED ELTABAKH PROCESSING AND QUERYING XML 1.
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.
The Semistructured-Data Model Programming Languages for XML Spring 2011 Instructor: Hassan Khosravi.
1 XML Data Management Extracting Data from XML: XPath Werner Nutt based on slides by Sara Cohen, Jerusalem.
1 XML Data Management XPath Principles Werner Nutt.
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.
Martin Kruliš by Martin Kruliš (v1.1)1.
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.
Lecture 23 XQuery 1.0 and XPath 2.0 Data Model. 2 Example 31.7 – User-Defined Function Function to return staff at a given branch. DEFINE FUNCTION staffAtBranch($bNo)
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.
XML Query languages--XPath. Objectives Understand XPath, and be able to use XPath expressions to find fragments of an XML document Understand tree patterns,
XPath.
XML path expressions CSE 350 Fall 2003.
Querying and Transforming XML Data
XML stands for Extensible Markup Language.
XML Path Language Andy Clark 17 Apr 2002.
Lecture 11: XML and Semistructured Data
Presentation transcript:

XPath Laks V.S. Lakshmanan UBC CPSC 534B

Overview data model recap XPath examples some advanced features summary

XPath in the beginning used to be part of XSLT –A formal semantics of patterns in XSLT (Phil Wadler) also influenced XLink, XPointer, resources: – –Galax (complete reference impl. of XQuery) (w3c.org – major resource many XML and other web related stuff, incl. XQuery, semantic web, etc.)

Example XML DB What is the name of this book? Raymond Smullyan Penguin 1970 Bentam Books New York Douglas R Hofstadter D.C. Dennett The Mind’s I: Reflections on Self and Soul 1981

Corresponding Tree root bib comments processing instructions root doc. element book titleauthorpublisher price ooo attribute element unordered usually, single valued. Exception: IDREFS. ordered. no apriori car- dinality constraint. note distinction between the two roots.

Simple Examples /bib/book/publisher answer: Penguin Bentam Books New York /bib/book/author/name what’s the answer? / -- returns root element, while /bib -- returns doc. root element, i.e., the bib element under the root.

Descendants /bib/book//address answer: New York /bib/book//mi answer: R //title answer: What is the name of this book? The Mind’s I: Reflections on Self and Soul Note: results ordered as per i/p document order.

Wildcard //author/* answer: Raymond Smullyan Douglas R Hofstadter why only two authors(’ info.) returned? Note: * matches any element. what does //* return? is the answer identical to that for /bib?

Attributes XML data model – diff. kinds of nodes: element, attribute, text, comment, processing instruction,... answer: ``15” contrast with answer for previous queries. what do you think it should return?

Branching & Qualifiers/Predicates /bib/book/author[mi] returns only second book. returns only first book. /bib/book[publisher[address][name]][price<20]//title returns the titles of books with a publisher who has a name & an address and with a price < 20.

Reaching out at other nodes XPath has the functions text(), node(), name(). Meanings illustrated below. /bib/book/publisher/text() answer: Penguin –why first pub doesn’t appear? /bib/book/node() returns all child nodes of book, regardless of type (attr, text, element). /bib/*/name() – returns tag of current element.

Mixing it all /bib/book[author[hobby=tennis]][title/text( )]//year what does it say? Features of XPath seen so far  tree pattern query. $x $y $w $z $x.tag=bib & $y.tag=comment & $z.tag=publisher... distinguished node

XPath – Summary / -- matches the root. /bib – matches bib element under root. bib – matches any bib element. * -- matches any element. bib/book – matches any book element under a bib element. bib//book – ditto, but at any depth. //book – matches any book element at any depth in the document. author|editor – matches any author or editor – matches any hobby attribute. -- matches any price attribute of an author at any depth of the doc. – what does it match?

XPath – The 13 axes child  descendant  attribute  descendant-or-self following following-sibling ancestor ancestor-or-self parent preceding preceding-sibling self namespace

Some Abbreviations child::book/child::author  book/author child::book/descendant::mi  book//mi child::first/parent::*  first/.. child::book/attribute::price  child::book/child::author/parent::*/child::y ear  book[author]/year /bib//mi[ancestor::book]  ? /bib//mi/ancestor::book//publisher  ? /bib//mi/ancestor::*//publisher  ?

More examples /bib/descendant::*[name()=address]  /bib//address /bib//book//first/parent::*[name()=author] /bib//book//mi[ancestor:*[name()=author or name()=editor]] navigation axes increase expressive power BUT, when schema is known, can often simplify XPath expressions

Simplifying XPE with schema /bib//book//first/parent::*[name()=author]  /bib//book//author[first] /bib//book//mi[ancestor:*[name()=author or name()=editor]  S /bib//book//*[name()=author or name()]//mi bib book authortitlepublisheryear firstmilastnameaddress example schema graph S editor * * +1? ? 1 ? ? 1 1

XPath, formally speaking XPE  a binary relation over document nodes: p(context node, answer node). basic cases: –“.” is, i.e., self (x,x) –“..” is parent, i.e., (current node, its parent) –publisher/address is (current node, address node reachable from current node via publisher child) –book/*/mi/../name()  book/*[mi]/name() what is the relationship captured by this XPE?

XPath, formally speaking Relative path expressions – every XPE E we have seen so far, except E may be used as a predicate or as an extension to an absolute XPE. Absolute XPE – how you get a (unary) query out of an XPE. E.g.: author/mi and publisher/address are relative XPEs. //author/mi, /bib/book[author/mi], /bib/book[author/mi][publisher/address]//year are all absolute XPEs. More details: see resources and stay tuned for homework.