XPath. Why XPath? Common syntax, semantics for [XSLT] [XPointer][XSLT] [XPointer] Used to address parts of an XML document Provides basic facilities for.

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.
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.
XPath s/xmljava/chapters/ch16.html.
Introduction to XLink Transparency No. 1 XML Information Set W3C Recommendation 24 October 2001 (1stEdition) 4 February 2004 (2ndEdition) Cheng-Chia Chen.
1 Overview of XPath. 2 XPATH XPath expressions are used to locate nodes in XML documents The list of nodes located by an XPath expression is called a.
XPath By Laouina Marouane. Outline  Introduction  Data Model  Expression Patterns Patterns Location Paths Location Paths  Example  XPath 2.0  Practice.
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.
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.
1 XPATH Modified Slides from Dr. Sagiv. 2 XPath A Language for Locating Nodes in XML Documents XPath expressions are written in a syntax that resembles.
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.
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.
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,
Representing Web Data: XML CSI 3140 WWW Structures, Techniques and Standards.
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.
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.
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.
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 Technologies for an Information Age:.opennet Extensible Style Language—XSLT Fall Semester 2001 MW 5:00 pm - 6:20 pm CENTRAL (not Indiana) Time Bryan.
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.
XPath.
{ XML Technologies } BY: DR. M’HAMED MATAOUI
XML Path Language Andy Clark 17 Apr 2002.
Modified Slides from Dr. Sagiv
More XML XML schema, XPATH, XSLT
Presentation transcript:

XPath

Why XPath? Common syntax, semantics for [XSLT] [XPointer][XSLT] [XPointer] Used to address parts of an XML document Provides basic facilities for manipulation of strings, numbers and booleans Uses a compact, non-XML syntax Gets its name from use of path notation as in URLs for navigating through the hierarchical structure

XPath Syntax XPath has a natural subset used for matching –Testing whether or not a node matches a pattern –This use of XPath is described in XSLTXSLT XPath models an XML document as a tree of nodes XPath defines a way to compute a string-value for each type of nodestring-value Primary syntactic construct in XPath is the expression (See expr production rule)

XPath Syntax XPath has a natural subset used for matching –Testing whether or not a node matches a pattern –This use of XPath is described in XSLTXSLT XPath models an XML document as a tree of nodes XPath defines a way to compute a string-value for each type of nodestring-value Primary syntactic construct in XPath is the expression (See expr production rule)

XPath Syntax XPath expression is evaluated to yield an object The four basic types of objects: –node-set (an unordered collection of nodes without duplicates) –boolean (true or false) –number (a floating-point number) –string (a sequence of characters) Expression evaluation occurs with respect to a context

Location Paths One important kind of expression is a location path Selects a set of nodes relative to the context node Location Path evaluation leads to node-set containing nodes selected by the location path

Location Paths 2 kinds of location path: –Relative location paths –Absolute location paths Relative location path consists of sequence of location steps separated by / Each step in turn selects a set of nodes relative to a context node An initial sequence of steps is composed together with a following step as follows The initial sequence of steps selects a set of nodes relative to a context node Each node in that set is used as a context node for the following step

Relative Location Paths Relative location path consists of sequence of location steps separated by / Each step in turn selects a set of nodes relative to a context node An initial sequence of steps is composed together with a following step as follows The initial sequence of steps selects a set of nodes relative to a context node

Relative Location Paths Each node in that set is used as a context node for the following step child::div/child::para selects the para element children of the div element children of the context node

Absolute Location Paths Consists of / optionally followed by a relative location path / by itself selects the root node of the document containing the context node If / followed by relative location path, the location path selects the set of nodes that would be selected by the relative location path relative to the root node

Location Step A location step has three parts: –An axis, specifying tree relationship between the nodes selected by the location step and the context node –A node test, specifying node type, name of nodes selected by the location step –Zero or more predicates, which use arbitrary expressions to further refine the set of nodes selected by the location step.

Location Step - Syntax Syntax: –Axis name, node test separated by a double colon, followed by zero or more expressions each in square brackets child::para[position()=1] child = name of axis, para = node test, [position()=1] = predicate

Location Step - Syntax Node-set selected by the location step is the node-set that results from generating an initial node-set from the axis and node-test, and then filtering that node-set by each of the predicates in turn

Axes Specifies the tree relationship between the nodes selected by the location step and the context node Different types of Axes: child axis contains the children of the context node descendant axis contains the descendants of the context node –descendant axis never contains attribute or namespace nodes

Axes Different types of Axes: parent axis contains parent of context node, if there is one ancestor axis contains the ancestors of the context node –Ancestor axis will always include the root node, unless the context node is the root node

Axes Different types of Axes: following-sibling axis contains all the following siblings of the context node –If the context node is attribute node or namespace node, the following-sibling axis is empty preceding-sibling axis contains all the preceding siblings of the context node –If the context node is attribute node or namespace node, the preceding-sibling axis is empty

Axes Different types of Axes: following axis contains all nodes in the same document as the context node that are after the context node in document order –Excludes any descendants, attribute, namespace nodes preceding axis contains all nodes in the same document as the context node that are before the context node in document order –Excludes any descendants, attribute, namespace nodes

Axes Different types of Axes: attribute axis contains the attributes of the context node –Axis will be empty unless the context node is an element namespace axis contains the namespace nodes of the context node –Axis will be empty unless the context node is an element self axis contains just the context node itself

Axes Different types of Axes: descendant-or-self axis contains the context node and the descendants of the context node ancestor-or-self axis contains the context node and the ancestors of the context node –ancestor axis will always include the root node

Axes The ancestor, descendant, following, preceding and self axes partition a document (ignoring attribute and namespace nodes): they do not overlap and together they contain all the nodes in the document

Node Tests Every axis has a principal node type If an axis can contain elements, then the principal node type is element For the attribute axis, the principal node type is attribute For the namespace axis, the principal node type is namespace For other axes, the principal node type is element

Node Tests A node test is true if and only if the type of the node is the principal node type node test * is true for any node of the principal node type –For example, child::* will select all element children of the context node node test text() is true for any text node –For example, child::text() will select the text node children of the context node

Node Tests node test node() is true for any node of any type whatsoever

Predicates Predicate filters a node-set with respect to an axis to produce a new node-set For each node in node-set to be filtered, the predicate is evaluated with that node as the context node, with the number of nodes in the node-set as the context size Predicate is evaluated by evaluating the expression(s) and converting the result to a boolean

Abbreviated Syntax child:: is the default axis. Can be omitted from a location step attribute:: can be abbreviated // is short for /descendant-or-self::node()/. is short for self::node().. is short for parent::node()

Location Paths - Exercises Explanations of each of these? child::para, child::*, child::text(), child::node() attribute::name, descendant::para, ancestor::div ancestor-or-self::div descendant-or-self::para child::chapter/descendant::para /descendant::olist/child::item child::para[position()=last()] following-sibling::chapter[position()=1] /child::doc/child::chapter[position()=5]/child::secti on[position()=2]

Locn Paths – Exercises (abbr.) Syntax of each of these? Select the para element children of the context node Select all element children of the context node Select all text node children of the context node Select the name attribute of the context node Select all the attributes of the context node Select the last para child of the context node Select all para grandchildren of the context node

Locn Paths – Exer. Soln. (abbr.) para para[last()] */para

Locn Paths – Exercises (abbr.) Syntax of each of the following? Select t he second section of the fifth chapter of the doc Select t he para element descendants of the chapter element children of the context node Select a ll the para descendants of the document root and thus selects all para elements in the same document as the context node Select t he context node

Locn Paths – Exer. Soln. (abbr.) Explanations of each of these? /doc/chapter[5]/section[2] chapter//para //para.

Locn Paths – Exercises (abbr.) Explanations of each of these?.//para.. //para.

Locn Paths – Exer. Soln. (abbr.).//para selects the para element descendants of the context node.. selects the parent of the context node //para selects all the para descendants of the document root and thus selects all para elements in the same document as the context node. selects the context node

Locn Paths – Exercises (abbr.) Syntax of the following: Select t he lang attribute of the parent of the context node Select t he fifth para child of the context node that has a type attribute with value warning S elect all the employee children of the context node that have both a secretary attribute and an assistant attribute

Locn Paths – Exer. Soln.

Expressions Refer to expressions syntax tree Refer to XPath Expressions Handbook

XPath Function Library Refer to XPath Function Library Handbook

Data Model XPath operates on an XML document as a tree The does not mandate any particular implementation 7 types of nodes: –Root Nodes –Element Nodes –Text Nodes –Attribute Nodes –Namespace Nodes –Processing Instruction Nodes –Comment Nodes

Data Model: Document Order The root node will be the first node Element nodes occur before their children Document order orders element nodes in order of the occurrence of their start-tag Attribute, Namespace nodes of an element occur before the children of the element Namespace nodes are defined to occur before the attribute nodes Relative order of namespace, attribute nodes is implementation-dependent

Data Model: Document Order Namespace nodes are defined to occur before the attribute nodes Relative order of namespace, attribute nodes is implementation-dependent Root nodes and element nodes have an ordered list of child nodes Every node other than the root node has exactly one parent, which is either an element node or the root node

Data Model: Root Node Root node is the root of the tree Element node for the document element is a child of the root node Root node also has as children processing instruction and comment nodes String-value of the root node is the concatenation of the string-values of all text node descendants of the root node in document order

Data Model: Element Node Is an element node for every element in the document Children of an element node are: –Element nodes –Comment nodes –Processing Instruction nodes –Text nodes String-value of an element node is the concatenation of the string-values of all text node descendants of the element node in document order

Data Model: Attribute Each element node has an associated set of attribute nodes Element is the parent of each of these attribute nodes An element has attribute nodes only for attributes that were explicitly specified in the start-tag or empty-element tag of that element or that were explicitly declared in the DTD with a default value

Data Model: Attribute Some attributes, such as xml:lang and xml:space, apply to all elements that are descendants of the element bearing the attribute, unless overridden with an instance of the same attribute on another descendant element. An attribute node has a string-value

Data Model: Namespace Nodes Each element has an associated set of namespace nodes, one for each distinct namespace prefix that is in scope for the element Element is the parent of each of these namespace nodes

Data Model: Namespace Nodes An element will have a namespace node: For every attribute on the element whose name starts with xmlns: ; For every attribute on an ancestor element whose name starts xmlns: unless the element itself or a nearer ancestor redeclares the prefix; For an xmlns attribute, if the element or some ancestor has an xmlns attribute, and the value of the xmlns attribute for the nearest such element is non-empty

Data Model: Namespace Nodes The string-value of a namespace node is the namespace URI that is being bound to the namespace prefix

Data Model: Processing Instruc. Is a processing instruction node for every processing instruction No such node for for any processing instruction that occurs within the document type declaration

Data Model: Comment Is a comment node for every comment No such node for any comment that occurs within the document type declaration String-value of comment is the content of the comment not including the opening

Data Model: Text Node Character data is grouped into text nodes As much character data as possible is grouped into each text node A text node never has an immediately following or preceding sibling that is a text node String-value of a text node is the character data A text node always has at least one character of data

Data Model: Text Node Characters inside comments, processing instructions and attribute values do not produce text nodes