Processing of structured documents Spring 2003, Part 7 Helena Ahonen-Myka.

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.
1 XSL – XML Stylesheet Language. 2 XSL XSL = XML Stylesheet Language XSL cosists of –XPath (navigation in documents) –XSLT (T for transformations) –XSLFO.
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.
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.
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.
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.
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.
Lecture 14. node-tests again: namespace-qualified node-tests I found a book. The fred:* node test admits only element in the fred namespace The match="book"
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
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
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.
Fall 2001 CSE3301 Query Languages for XML. Fall 2001 CSE3302 Why a query language? Extracting, Restructuring, Integration, Browsing… XML-QL
XPath Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
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.
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.
Processing of structured documents Part 3. 2 XML Schema (continues…) zBuilding content models… za simplified view of the allowed structure of a complex.
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
Modified Slides from Dr. Sagiv
XML DOCUMENTS & DATABASES
Presentation transcript:

Processing of structured documents Spring 2003, Part 7 Helena Ahonen-Myka

2 XML Path Language (XPath) The ability to navigate through XML documents is needed in many applications of XML querying of XML documents creation of hypertext links to objects that do not have unique identifiers formatting of document components for presentation

3 XML Path Language (XPath) XPath provides common syntax and semantics to address parts of an XML document basic facilities for manipulation of strings, numbers and booleans XPath uses a compact, non-XML syntax to facilitate use of XPath within URIs and XML attribute values

4 XML Path Language (XPath) Use e.g. as a pattern in XSLT: …

5 XML Path Language (XPath) XPath operates on an XML document as a tree every element in an XML document has a specific and unique contextual location any element in the document can be identified by the steps it would take to reach it, either from the root element, or from some other fixed starting location

6 Expressions The primary syntactic construct in XPath is the expression an expression is evaluated to yield an object, which has one of the following types node-set (unordered) boolean (true or false) number string (in XPath 2.0 also more types)

7 Location paths relative location paths a path that starts from an existing location sequence of one or more location steps separated by / steps are composed from left to right the initial step selects a set of nodes relative to the context node each node in this set is used as a context node for the following step the sets of nodes identified by that step are unioned together e.g. child:name/child:fname

8 Location paths An absolute location path consists of / optionally followed by a relative location path A / by itself selects the root node of the document if / is followed by a relative path, then the location path selects the set of nodes that would be selected by the relative location path relative to the root node

9 Location steps A location step has three parts an axis: the tree relationship between the nodes selected by the location step and the context node a node test: the node type and name of the 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 syntax: axis::node-test[expr][expr]… e.g. child::para[position()=1]

10 Location steps The 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 the initial node-set consists of the nodes having the relationship to the context node specified by the axis, and having the node type and name specified by the node test

11 Axes child descendant parent ancestor following-sibling empty, if the context node is an attribute node or namespace node preceding-sibling empty, if the context node is an attribute node or namespace node

12 Axes following all nodes in the same document as the context node that are after the context node in document order, excluding any descendants and excluding attribute nodes and namespace nodes preceding all nodes in the same document as the context node that are before the context node in document order, excluding any ancestors and excluding attribute nodes and namespace nodes

13 Axes attribute attribute nodes of the context node empty unless the context node is an element namespace namespace nodes of the context node empty unless the context node is an element self the context node itself descendant-or-self, ancestor-or-self

14 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

15 Node tests Every axis has a principal node type for the attribute axis: attribute for the namespace axis: name space for other axes: element a node test both name and type have to match child::para selects the para element children of the context node if the context node has no para children, it will select an empty set of nodes

16 Node tests node test node() represents any node node tests text(), comment(), and processing-instruction() represent any object of these specific types a node test * is true for any node of the principal node type child::* selects all element children of the context node attribute::* selects all attributes of the context node

17 Abbreviated syntax child:: -> can be omitted from a location step; child is the default axis child::div/child::para -> div/para attribute:: child::para[attribute::type=”warning”] -> /descendant-or-self::node()/ -> // //para selects any para element in the document div//para selects all para descendants of div children (of the context node)

18 Abbreviated syntax self::node() ->. (fullstop).//para selects all para descendant elements of the context node parent::node() ->..../title selects the title children of the parent of the context node

19 Predicates An axis is either a forward axis or a reverse axis forward axis: an axis that only ever contains the context node or nodes that are after the context node in document order reverse axis: an axis that only ever contains the context node or nodes that are before the context node in document order

20 Predicates the proximity position of a member of a node- set with respect to an axis: the position of the node in the node-set ordered in document order if the axis is a forward axis reverse order if the axis is a reverse axis the first position is 1 a predicate filters a node-set to produce a new node-set for each node in the node-set, the predicate expression is evaluated with that node as the context node and with the proximity position of the node in the node-set

21 Predicates If the predicate expression evaluates to true for that node, the node is included in the new node-set the result of the evaluation is converted to a boolean if the result is a number, the result is true if the number is equal to the context position otherwise, the result will be converted as if by a call to the function boolean (see below) e.g. para[3] equals para[position()=3]

22 Predicates Contained element tests the name of an element can appear in a predicate filter -> represents an element that must be present as a child note[title] a note element is only selected if it directly contains a title element note[title=”first note”] true, if the content of the element is ’first note’ note[id(”123”)]

23 Predicates Attribute tests every ’para’ element with a ’type’ attribute value of ’secret’

24 Expressions boolean operators: or, and comparisons: =, !=, =, > in XML documents: < has to be converted to < numeric operators: +, -, *, div, mod

25 Core functions some functions number last() number position() number count(node-set) node-set id(object) e.g. id(”foo”) selects the element with unique ID foo boolean starts-with(string, string) returns true if the first string starts with the second boolean contains(string, string) returns true if the first string contains the second

26 Examples para selects the para element children of the context node * selects all element children text() selects all text node selects the name selects all the attributes para[1] selects the first para child para[last()] selects the last para child */para selects all para grandchildren /doc/chapter[5]/section[2] selects the second section of the fifth chapter of the doc (root)

27 Examples chapter//para selects the para element descendants of the chapter element children //para selects all the para descendants of the document root and thus selects all the para elements in the same document as the context node //olist/item selects all the item elements in the same document as the context node that have an olist parent. selects the context node.//para selects the para element descendants.. selects the selects the lang attribute of the parent

28 Examples 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 selects the fifth para child of the context node if that child has a type attribute with value warning

29 Examples chapter[title=”Introduction”] selects the chapter children of the context node that have one or more title children with string-value equal to Introduction chapter[title] selects the chapter children of the context node that have one or more title children selects all the employee children of the context node that have both a secretary attribute and an assistant attribute