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.

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:
XPath. XPath Used to access part of XML document Used to access part of XML document Compact, non-XML syntax Compact, non-XML syntax Use a pattern expression.
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.
SDPL 2003Notes 5: XSLT1 5. Document Transformations n XSLT (W3C Rec. November 1999) –A language for transforming XML documents »representative of tree-based.
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 Concepts Lecture 7. XML Display Options What can XSL Transformations do? generation of constant text suppression of content moving text (e.g., exchanging.
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.
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.
Cornell CS 502 More XML XML schema, XPATH, XSLT CS 502 – Carl Lagoze – Cornell University.
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
10/06/041 XSLT: crash course or Programming Language Design Principle XSLT-intro.ppt 10, Jun, 2004.
XSLT Brent P. Christie Major USMC. XSLT Overview  What is XSLT? –XSL is the Extensible Style Language. –It has two parts: the transformation language.
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.
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.
Representing Web Data: XML CSI 3140 WWW Structures, Techniques and Standards.
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,
Processing of structured documents Spring 2002, Part 2 Helena Ahonen-Myka.
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.
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.
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.
WPI, MOHAMED ELTABAKH PROCESSING AND QUERYING XML 1.
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.
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.
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.
Beginning XML 4th Edition.
{ XML Technologies } BY: DR. M’HAMED MATAOUI
XML Path Language Andy Clark 17 Apr 2002.
XPath 9-May-19.
More XML XML schema, XPATH, XSLT
XML DOCUMENTS & DATABASES
Xpath October 16, 2019 ICS 541: Xpath.
XPath 7-Dec-19.
Presentation transcript:

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 syntax and semantics for functionality shared between XSLT and XPointer. n Primary purpose: Address ‘parts’ of an XML document, and provide basic facilities for manipulation of strings, numbers and booleans. n W3C Recommendation. November 16, 1999 n Latest version:

XPath Introduction Introduction Data Model Data Model Expressions Expressions Location Paths Location Paths Core Function Library Core Function Library Conclusion Conclusion

Introduction XPath uses a compact, string-based, rather than XML element-based syntax. XPath uses a compact, string-based, rather than XML element-based syntax. Operates on the abstract, logical structure of an XML document (tree of nodes) rather than its surface syntax. Operates on the abstract, logical structure of an XML document (tree of nodes) rather than its surface syntax. Uses a path notation (like URLs) to navigate through this hierarchical tree structure. Uses a path notation (like URLs) to navigate through this hierarchical tree structure. Introduction

Introduction Cont. Defines a way to compute a string-value for each type of node: element, attribute, text. Defines a way to compute a string-value for each type of node: element, attribute, text. Supports Namespaces. Supports Namespaces. Name of a node (a pair consisting of a local part and namespace URI). Name of a node (a pair consisting of a local part and namespace URI). Expression (Expr) is the primary syntactic construct. Expression (Expr) is the primary syntactic construct. Introduction

Data Model n Treats an XML document as a logical tree n This tree consists of 7 nodes:  Root Node – the root of the document  Element Nodes – one for each element in the document  Unique ID’s  Attribute Nodes  Namespace Nodes  Processing Instruction Nodes  Comment Nodes  Text Nodes n The tree structure is ordered and reads from top to bottom and left to right Data Model

Data Model Example For this simple doc: <doc> Some emphasis here. Some emphasis here. Some more stuff. Some more stuff. </doc> Might be represented as: root<doc> text text text text text texttext Data Model

Expression Evaluated to yield an object of 4 basic types. Evaluated to yield an object of 4 basic types.  node-set (unordered collection of nodes w/o duplicates).  boolean (true/false)  number (float)  string (sequence of UCS chars) Evaluation occurs with respect to a context. (XSLT/XPointer specified context) Evaluation occurs with respect to a context. (XSLT/XPointer specified context) Parsed by dividing the character string into tokens and then parsing the resulting sequence of tokens. Parsed by dividing the character string into tokens and then parsing the resulting sequence of tokens. Location paths select a set of nodes relative to the context node. Location paths select a set of nodes relative to the context node. Expression

Location Paths LocationPath (most important construct) describes a path from 1 point to another. LocationPath (most important construct) describes a path from 1 point to another. u Analogy: Set of street directions. “Second store on the left after the third light” LocationPath provides the mechanism for ‘addressing’ items in an XML doc LocationPath provides the mechanism for ‘addressing’ items in an XML doc Two types of paths: Relative & Absolute Two types of paths: Relative & Absolute Composed of a series of steps (1 or more) and optional predicates Composed of a series of steps (1 or more) and optional predicates LocationPath

Location Paths n General syntax: LocationPath::= RelativeLocationPath | AbsoluteLocationPath LocationPath::= RelativeLocationPath | AbsoluteLocationPath n Verbose syntax (has syntactic abbreviations for common cases) Examples (unabbreviated) u child::para selects the para element children of the context node u child::* selects all element children of the context node u attribute::name selects the name attribute of the context node u ancestor::div selects all div ancestors of the context node u self::para selects the context node if it is a para element (otherwise selects nothing) u child::*/child::para selects all para grandchildren of the context node u / selects the document root (which is always the parent of the document element) LocationPath

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) u 0 or more predicates (arbitrary expressions to refine the selected set of nodes) n Syntax: Step ::= Axis Specifier NodeTest Predicate* | AbbreviatedStep Axis Specifier ::= AxisName ‘::’ |AbbreviatedAxisSpecifier |AbbreviatedAxisSpecifier ex: child::para[position( )=1] =>child is the name of the axis, para is the node test, and [position()=1] is a predicate n 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. ex:descendant::para =>selects the para element descendants of the context node. =>selects the para element descendants of the context node. LocationPath

Location Steps Axes Axes  13 axes defined in XPath  Ancestor, ancestor-or-self  Attribute  Child  Descendant, descendant-or-self  Following  Preceding  Following-sibling, preceding-sibling  Namespace  Parent  Self Node test Node test  Identifies type of node. Evaluates to true/false  Can be a name or function to evaluate/verify type Predicate Predicate  XPath boolean expressions in square brackets following the basis(axis & node test)

Examples n Axis and Node Test: child::para selects the para elements that are children of the context node preceding-sibling::para selects the preceding para elements that are siblings to the context node n Basis and Predicate: child::para[3] selects the 3 rd para of the children of the context node child::para[attribute::type=“warning”] selects all para children of the context node that have a type attribute with value warning selects the fifth para child of the context node that has a type attribute with value warning LocationPath

Abbreviated Syntax n child:: can be omitted from a location step. (child is the default axis) div/para is equivalent to child::div/child::para n attribute:: can be abbreviated n // is short for /descendant-or-self::node()/ n A location step of. is short for self::node() ex:.//para is short for self::node()/descendant-or-self::node()/child::para n Location step of.. is short for parent::node() LocationPath

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

Basics n A VariableReference evaluates to the value to which the variable name is bound in the set of variable bindings in the context. It is an error if the variable name is not bound to any value in the set of variable bindings in the expression context. n Parentheses may be used for grouping Expr::= OrExpr PrimaryExpr::= VariableReference | ’(‘ Expr ‘)’ | Literal | Number | FunctionCall

Function Calls n Function call expression is evaluated by using the FunctionName to identify a function in the expression evaluation context function library, evaluating each of the Arguments, converting each argument tot he type required by the function, and finally calling the function, passing it the converted arguments. Error, if the number of args is wrong or if an arg cannot be converted to the required type. The result of the FunctionCall expression is the result returned by the function. n An argument is converted to type string (as if calling the string function), converted to type boolean....converted to type number... n An argument that is not of type node-set cannot be converted to a node-set. n FunctionCall ::= FunctionName ‘(‘(Argument (‘,’ Argument)*)?’)’ Argument ::= Expr

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

Booleans n A boolean can only have two values: true or false n The following expressions can be evaluated: u or u and u =, != u =, > n Special rules apply when comparing node-sets as booleans

Numbers n A number represents a floating-point number n The numeric operators convert their operands to numbers n Operators include: u +, -, *, /, %, and union

Strings n Strings consist of a sequence of zero or more character n A character is defined in the XML Recommendation

Lexical Structure n When tokenizing, the longest possible token is returned

Core Function Library n XPath defines a core set of functions and operators n All implementations of Xpath must implement the core function library n Node Set Functions list/item[position() mod2 = 1] selects all odd number element of a list id)(“foo”)/child::para[position()=5] selects the 5 th para child of the element with the unique ID foo n String Functions substring(“12345”, 0, 3) returns “12” n Boolean Functions boolean true() returns “true” n Number Functions number sum(node-set) returns the sum of the nodes Core Library

Conclusion XPath provides a concise and intuitive way to address into XML documents XPath provides a concise and intuitive way to address into XML documents Standard part of the XSLT and XPointer specifications Standard part of the XSLT and XPointer specifications 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