XPath Tao Wan March 04, 2002. What is XPath? n A language designed to be used by XSL Transformations (XSLT), Xlink, Xpointer and XML Query. n Primary.

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.
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.
SDPL 2002Notes 5: XSLT1 5. Document Transformations n XSLT (W3C Rec. November 1999) –A language for transforming XML documents »representative of tree-based.
XML 6.6 XPath 6. What is XPath? XPath is a syntax used for selecting parts of an XML document The way XPath describes paths to elements is similar to.
2-Jun-15 XPath. 2 What is XPath? XPath is a syntax used for selecting parts of an XML document The way XPath describes paths to elements is similar to.
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)
XPath By Laouina Marouane. Outline  Introduction  Data Model  Expression Patterns Patterns Location Paths Location Paths  Example  XPath 2.0  Practice.
Managing XML and Semistructured Data Lecture 6: XPath Prof. Dan Suciu Spring 2001.
XPath Carissa Mills Jill Kerschbaum. What is XPath? n A language designed to be used by both XSL Transformations (XSLT) and XPointer. n Provides common.
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.
Cornell CS 502 More XML XML schema, XPATH, XSLT CS 502 – Carl Lagoze – Cornell University.
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
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.
XP ATH - XML Path Language. W HAT IS XP ATH ? XPath, the XML Path Language, is a query language for selecting nodes from an XML document.query languagenodesXML.
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.
CSE3201/CSE4500 XPath. 2 XPath A locator for elements or attributes in an XML document. XPath expression gives direction.
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.
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.
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,
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.
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
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.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
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.
ECA 228 Internet/Intranet Design I XSLT Example. ECA 228 Internet/Intranet Design I 2 CSS Limitations cannot modify content cannot insert additional text.
XSLT part of XSL (Extensible Stylesheet Language) –includes also XPath and XSL Formatting Objects used to transform an XML document into: –another XML.
IS432: Semi-Structured Data Dr. Azeddine Chikh. 6. XML Path (XPath)
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.
SDPL 2001Notes 5: XSLT1 5. Document Transformations n XSLT (W3C Rec. Nov-99) –A language for transforming XML documents »representative of features common.
CSE 636 Data Integration Fall 2006 XML Query Languages XPath.
WPI, MOHAMED ELTABAKH PROCESSING AND QUERYING XML 1.
[ Part III of The XML seminar ] Presenter: Xiaogeng Zhao A Introduction of XQL.
XPath Presented by Kushan Athukorala. 2 Agenda XPath XPath Terminology Selecting Nodes Predicates.
1 XML Data Management XPath Principles Werner Nutt.
More XML XPATH, XSLT CS 431 – February 23, 2005 Carl Lagoze – Cornell University.
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.
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 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.
CITA 330 Section 5 XPath. XSL XSL (Extensible Stylesheet Language) is the standard language for writing stylesheets to transform XML documents among different.
5 Copyright © 2004, Oracle. All rights reserved. Navigating XML Documents by Using XPath.
XSLT, XML Schema, and XPath Matt McClelland. Introduction XML Schema ▫Defines the content and structure of XML data. XSLT ▫Used to transform XML documents.
XPath.
{ XML Technologies } BY: DR. M’HAMED MATAOUI
XML Path Language Andy Clark 17 Apr 2002.
More XML XML schema, XPATH, XSLT
XML DOCUMENTS & DATABASES
Presentation transcript:

XPath Tao Wan March 04, 2002

What is XPath? n A language designed to be used by XSL Transformations (XSLT), Xlink, Xpointer and XML Query. n Primary purpose: Address ‘part’ of an XML document, and provide basic facilities for manipulation of strings, numbers and booleans.

Outline Introduction Introduction Data Model Data Model Xpath Syntax Xpath Syntax Location Path Location Path General Xpath Expressions General Xpath Expressions Core Function Library Core Function Library XPath utilities XPath utilities Conclusion Conclusion

Introduction n W3C Recommendation. November 16, 1999 n Latest version: n XPath uses a compact, string-based, rather than XML element-based syntax. n Operates on the abstract, logical structure of an XML document rather than its surface syntax. n Uses a path notation (like in URLs) to navigate through this hierarchical tree structure. Introduction

Introduction Cont. Xpath models an XML doc as a tree of nodes and defines a way to compute a string- value for each type of node. Xpath models an XML doc as a tree of nodes and defines a way to compute a string- value for each type of node. Supports Namespaces. Supports Namespaces. Expression (Expr) is the primary syntactic construct of Xpath. Expression (Expr) is the primary syntactic construct of Xpath. Introduction

Data Model n The way to represent an XML document. n This tree consists of 7 nodes:  Root Node  Element Nodes  Attribute Nodes  Namespace Nodes  Processing Instruction Nodes  Comment Nodes  Text Nodes n The tree structure is ordered in order of the occurrence of nodes’ start-tag in the XML doc. Data Model

Data Model Example IDG books Rick Hull Simon North XML complete 1997 Freeman Jeffrey D. Ullman Principles of Database 1998 IDG books Rick Hull Simon North XML complete 1997 Freeman Jeffrey D. Ullman Principles of Database 1998 </bib> Data Model

Xpath Syntax Expression is the primary syntactic construct in XPath Expression is the primary syntactic construct in XPath Evaluated to yield an object of 4 basic types. Evaluated to yield an object of 4 basic types.  node-set (unordered collection of nodes without duplicates).  boolean (true/false)  number (float)  string (sequence of UCS chars) Expression Evaluation occurs will respect to a context. (XSLT/XPointer specified context) Expression Evaluation occurs will respect to a context. (XSLT/XPointer specified context) Location path is one important kind of expression. Location path is one important kind of expression.  Location paths select a set of nodes relative to the context node. Expression

Location Path Location Path provides the mechanism for ‘addressing’ parts of an XML doc, similar to file system addressing. Location Path provides the mechanism for ‘addressing’ parts of an XML doc, similar to file system addressing. Ex: /book/year (select all the year elements that have a book parent) Ex: /book/year (select all the year elements that have a book parent) Every location path can be expressed using a straightforward but rather verbose syntax: Every location path can be expressed using a straightforward but rather verbose syntax:  unabbreviated syntax (verbose syntax) Ex: child::* (select all element children of the context node)  abbreviated syntax Ex. * (equivalent to unabbreviation above) Location Path

Location Path Cont. Two types of paths: Relative & Absolute Two types of paths: Relative & Absolute  Relative location path: consists of a sequence of one or more location steps separated by /  absolute location path: consists of / optionally followed by a relative location path Composed of a series of steps (1 or more) Composed of a series of steps (1 or more) Location Path Ex. Child::bib/child::book (select the book element children of the bib element children of the context node) Ex. / (select the root node of the document containing the context node)

Location Path Examples n Verbose syntax (has syntactic abbreviations for common cases) Examples (unabbreviated) u child::book selects the book element children of the context node node u child::* selects all element children of the context node u attribute::price selects the price attribute of the context node u descendant::book selects all book descendants of the context node u self::book selects the context node if it is a book element (otherwise selects nothing) u child::*/child::book selects all book grandchildren of the context node u / selects the document root (which is always the parent of the document element) parent of the document element) Location Path

Location Steps n 3 parts u axis (specifies relationship btwn selected nodes and the context node) u node test (specifies the node type and expanded-name of selected nodes) u predicates ( arbitrary expressions to refine the selected set of nodes ) n The syntax for location step is the axis name and node test separated by a double colon followed by zero or more expressions, each in square bracket. n Evaluate a location step is to generate an initial node-set from axis ( relationship to context node ) and node-test ( node-type and expanded-name ), then filter that node-set by each of the predicates in turn. Location Step ex: child::book[position( )=1] child is the name of the axis, book is the node test, and [position()=1] is a predicate ex: descendant::book[position( )=1] selects the all book element descendants of the context node firstly, then filter the one which is first book descendant of context node.

Location Steps Axes Axes  13 axes defined in XPath  Ancestor, ancestor-or-self  Attribute  Child  Descendant, descendant-or-self  Self  Following  Preceding  Following-sibling, preceding-sibling  Namespace  Parent Node test Node test  Identifies type and expanded-name of node.  Can use a name, wildcard or function to evaluate/verify type and name. ex. Child::text() select the text node children of context node. ex. Child::text() select the text node children of context node. Child::book select book element children of context node. Child::book select book element children of context node. Attribute::* select all attribute children of context node. Attribute::* select all attribute children of context node. Location step We’ve only seen these, so far

Location Step Cont. Predicate Predicate  A predicate filters a node-set with respect to an axis to produce a new node-set.  Use XPath expressions (normally, boolean expressions) in square brackets following the basis (axis & node test). Ex. Child::book[attribute::price=“25”] Ex. Child::book[attribute::price=“25”] (select all book children of the context node that have a price attribute with value 25. (select all book children of the context node that have a price attribute with value 25.  A predicateExpr is evaluated by evaluating the Expr and converting the result to a boolean (True or False)

Examples n Axis and Node Test: descendant::publisher (selects the publisher elements that are descendant of the context node) attributes::* (selects all attributes of the context node) n Basis and Predicate: child::book[3] (selects the 3 rd book of the children of the context node) child::*[self::author or self::year][position()=last()] (selects the last author or year child of the context node) child::book[attribute::page=“400”][5] (selects the fifth book child of the context node that has a page attribute with value 400) Location Path

Abbreviated Syntax n Abbreviated syntax is the simpler way to express location path. n For common case, abbreviation can be used to express concisely (not every case). n Each abbreviation can be converted to unabbreviated one. Location Path child:: can be omitted from a location step (child is the default axis) ex. bib/book is equivalent to child::bib/child::book A location step of. is short for self::node() ex:.//book is short for self::node()/descendant-or-self::node()/child::book Location step of.. is short for parent::node() ex.../title is short for parent::node()/child::title // is short for /descendant-or-self::node()/ ex. Book//author is short for book/descendant-or-self::node()/child::author attribute:: can be abbreviated ex. is short for child::book[attribute::price=“25”]

Expressions Function Calls Function Calls Node-sets Node-sets Booleans Booleans Numbers Numbers Strings Strings Expressions Function Calls

n Function call expression is evaluated by using the FunctionName to identify a function in the expression evaluation context function library. n An argument is converted u to type string (as if calling the string function), u to type boolean (as if calling the Boolean function), u to type number (as if calling the number function), u An argument that is not of type node-set cannot be converted to a node-set. Ex. position() function returns the current node’s position in the context node list as a number. Ex. position() function returns the current node’s position in the context node list as a number. Expressions

Function Calls Function Calls Node-sets Node-sets Booleans Booleans Numbers Numbers Strings Strings Expressions

Node-sets n A location path can be used as an expression. n The expression returns the set of nodes selected by the path. Expressions

Function Calls Function Calls Node-sets Node-sets Booleans Booleans Numbers Numbers Strings Strings Expressions

Booleans n A boolean can only have two values: true or false n The following operators can be used in boolean expressions or combine two boolean expressions according to the usual rules of boolean logic: u or u and u =, != u =, > Ex. Book=‘XML complete’ or book=‘Principles of Database Expressions

Function Calls Function Calls Node-sets Node-sets Booleans Booleans Numbers Numbers Strings Strings Expressions

Numbers n A number represents a floating-point number, no pure integers exist in Xpath. n The basic arithmetic operators include: +, -, *, div and mod. div 10 Expressions

Function Calls Function Calls Node-sets Node-sets Booleans Booleans Numbers Numbers Strings Strings Expressions

Strings n Strings consist of a sequence of zero or more character. n May be enclosed in either single or double quotes. n Comparison operators: =, != Expressions

Core Function Library n XPath defines a core set of functions to evaluate expressions. n All implementations of Xpath must implement the core function library. n Four type of functions: u Node Set Functions: operate on or return info about node sets. u String Functions: are used for basic string operations. Ex. substring(“12345”, 0, 3) returns “12” Ex. substring(“12345”, 0, 3) returns “12” u Boolean Functions: all return true or false. u Number Functions: are used for basic number operations. Core Library

Xpath Utilities n Miscellaneous utilities related to Xpath n n XPath Visualiser: u This is a powerful tool for the evaluation of an XPath expression and visual presentation of the resulting node-set. u allowing you to experiment with XPath for finding the correct expression. u The display of the XML source document is similar to the default IE display with the same syntax color and collapsible & expandable container nodes. IE display with the same syntax color and collapsible & expandable container nodes. u very straightforward XPath learning process. Xpath Utilities

XPath Visualiser Tree View of XML Doc Xpath input Xpath evaluating result Context Node Result is highlighted Xpath Utilities

Conclusion Xpath is complete pattern match language. Xpath is complete pattern match language. Provides an concise way for addressing parts of an XML document. Provides an concise way for addressing parts of an XML document. Base for XSLT, Xpointer and XML Query WG. Supported by W3C. Base for XSLT, Xpointer and XML Query WG. Supported by W3C. Implementing XPath basically requires learning the abbreviated syntax of location path expressions and the functions of the core library. Implementing XPath basically requires learning the abbreviated syntax of location path expressions and the functions of the core library. Conclusion

Reference n XML Path Language (XPath) V n XML in a Nutshell ch09.html ch09.html n Managing XML and Semistructured Data SES/590DS/06xpath.htm n Xpath utilities Xpath Reference