Xpath October 16, 2019 ICS 541: Xpath.

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.
Internet Technologies1 1 Lecture 4: Programming with XSLT.
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.
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.
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.
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 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 neral/examples.html.
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.
XML –Query Languages, Extracting from Relational Databases ADVANCED DATABASES Khawaja Mohiuddin Assistant Professor Department of Computer Sciences Bahria.
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
ECA 228 Internet/Intranet Design I Intro to XSL. ECA 228 Internet/Intranet Design I XSL basics W3C standards for stylesheets – CSS – XSL: Extensible Markup.
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.
1/17 ITApplications XML Module Session 7: Introduction to XPath.
Introduction to XPath Web Engineering, SS 2007 Tomáš Pitner.
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.
WORKING WITH XSLT AND XPATH
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.
ECA 228 Internet/Intranet Design I XSLT Example. ECA 228 Internet/Intranet Design I 2 CSS Limitations cannot modify content cannot insert additional text.
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.
XPath Presented by Kushan Athukorala. 2 Agenda XPath XPath Terminology Selecting Nodes Predicates.
1 XML Data Management XPath Principles Werner Nutt.
XPath. XPath, the XML Path Language, is a query language for selecting nodes from an XML document. The XPath language is based on a tree representation.
XP New Perspectives on XML, 2 nd Edition Tutorial 7 1 TUTORIAL 7 CREATING A COMPUTATIONAL STYLESHEET.
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.
XPath.
Data Structures and Design in Java © Rick Mercer
Beginning XML 4th Edition.
XML and XPath.
Xpath creation.
Lecture XSLT.
{ XML Technologies } BY: DR. M’HAMED MATAOUI
XML Path Language Andy Clark 17 Apr 2002.
Lecture 36 Section 12.2 Mon, Apr 23, 2007
CE 221 Data Structures and Algorithms
CE 221 Data Structures and Algorithms
Modified Slides from Dr. Sagiv
CS210- Lecture 9 June 20, 2005 Announcements
Modified Slides from Dr. Sagiv
XPath 9-May-19.
XPath 7-Dec-19.
Presentation transcript:

Xpath October 16, 2019 ICS 541: Xpath

Objectives Introduction to Xpath October 16, 2019 ICS 541: Xpath

- Lecture outline Introduction Paths slashes Brackets and last() Stars Attributes Axes Arithmetic expression Equality test Boolean expressions Some Xpath functions October 16, 2019 ICS 541: Xpath

-- 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 the way an operating system describes paths to files XPath is almost a small programming language; it has functions, tests, and expressions XPath is a W3C standard October 16, 2019 ICS 541: Xpath

-- Terminology library is the parent of book; book is the parent of the two chapters The two chapters are the children of book, and the section is the child of the second chapter The two chapters of the book are siblings (they have the same parent) library, book, and the second chapter are the ancestors of the section The two chapters, the section, and the two paragraphs are the descendents of the book <library> <book> <chapter> </chapter> <section> <paragraph/> </section> </book> </library> October 16, 2019 ICS 541: Xpath

- Paths Xpath Operating System /library = the root element (if named library ) /library/book/chapter/section = every section element in a chapter in every book in the library section = every section element that is a child of the current element . = the current element .. = parent of the current element /library/book/chapter/* = all the elements in /library/book/chapter Operating System / = the root directory /users/dave/foo = the file named foo in dave in users foo = the file named foo in the current directory . = the current directory .. = the parent directory /users/dave/* = all the files in /users/dave October 16, 2019 ICS 541: Xpath

- Slashes A path that begins with a / represents an absolute path, starting from the top of the document Example: /email/message/header/from Note that even an absolute path can select more than one element A slash by itself means “the whole document” A path that does not begin with a / represents a path starting from the current element Example: header/from A path that begins with // can start from anywhere in the document Example: //header/from selects every element from that is a child of an element header This can be expensive, since it involves searching the entire document October 16, 2019 ICS 541: Xpath

- Brackets and last() A number in brackets selects a particular matching child Example: /library/book[1] selects the first book of the library Example: //chapter/section[2] selects the second section of every chapter in the XML document Example: //book/chapter[1]/section[2] Only matching elements are counted; for example, if a book has both sections and exercises, the latter are ignored when counting sections The function last() in brackets selects the last matching child Example: /library/book/chapter[last()] You can even do simple arithmetic Example: /library/book/chapter[last()-1] October 16, 2019 ICS 541: Xpath

- Stars A star, or asterisk, is a “wild card”--it means “all the elements at this level” Example: /library/book/chapter/* selects every child of every chapter of every book in the library Example: //book/* selects every child of every book (chapters, tableOfContents, index, etc.) Example: /*/*/*/paragraph selects every paragraph that has exactly three ancestors Example: //* selects every element in the entire document October 16, 2019 ICS 541: Xpath

- Attributes … You can select attributes by themselves, or elements that have certain attributes Remember: an attribute consists of a name-value pair, for example in <chapter num="5">, the attribute is named num To choose the attribute itself, prefix the name with @ Example: @num will choose every attribute named num Example: //@* will choose every attribute, everywhere in the document To choose elements that have a given attribute, put the attribute name in square brackets Example: //chapter[@num] will select every chapter element (anywhere in the document) that has an attribute named num October 16, 2019 ICS 541: Xpath

… -- Attributes //chapter[@num] selects every chapter element with an attribute num //chapter[not(@num)] selects every chapter element that does not have a num attribute //chapter[@*] selects every chapter element that has any attribute //chapter[not(@*)] selects every chapter element with no attributes October 16, 2019 ICS 541: Xpath

-- Values of attributes //chapter[@num=“3”] selects every chapter element with an attribute num with value 3 The normalize-space() function can be used to remove leading and trailing spaces from a value before comparison Example: //chapter[normalize-space(@num)="3"] October 16, 2019 ICS 541: Xpath

- Axes An axis (plural axes) is a set of nodes relative to a given node; X::Y means “choose Y from the X axis” self:: is the set of current nodes (not too useful) self::node() is the current node child:: is the default, so /child::X is the same as /X parent:: is the parent of the current node ancestor:: is all ancestors of the current node, up to and including the root descendant:: is all descendants of the current node (Note: never contains attribute or namespace nodes) preceding:: is everything before the current node in the entire XML document following:: is everything after the current node in the entire XML document October 16, 2019 ICS 541: Xpath

Axes (outline view) Starting from a given node, the self, preceding, following, ancestor, and descendant axes form a partition of all the nodes (if we ignore attribute and namespace nodes) <library> <book> <chapter/> <chapter> <section> <paragraph/> <paragraph/> </section> </chapter> <chapter/> </book> <book/> </library> //chapter[2]/self::* //chapter[2]/preceding::* //chapter[2]/following::* //chapter[2]/ancestor::* //chapter[2]/descendant::* October 16, 2019 ICS 541: Xpath

Axes (tree view) ancestor paragraph[1] paragraph[2] section[1] chapter[2] chapter[1] chapter[3] book[1] book[2] library following preceding self Starting from a given node, the self, ancestor, descendant , preceding, and following axes form a partition of all the nodes (if we ignore attribute and namespace nodes) descendant October 16, 2019 ICS 541: Xpath

-- Axis Examples //book/descendant::* is all descendants of every book //book/descendant::section is all section descendants of every book //parent::* is every element that is a parent, i.e., is not a leaf //section/parent::* is every parent of a section element //parent::chapter is every chapter that is a parent, i.e., has children /library/book[3]/following::* is everything after the third book in the library October 16, 2019 ICS 541: Xpath

-- More axes ancestor-or-self:: ancestors plus the current node descendant-or-self:: descendants plus the current node attribute:: is all attributes of the current node namespace:: is all namespace nodes of the current node preceding:: is everything before the current node in the entire XML document following-sibling:: is all siblings after the current node Note: preceding-sibling:: and following-sibling:: do not apply to attribute nodes or namespace nodes October 16, 2019 ICS 541: Xpath

-- Abbreviations for axes (none) is the same as child:: @ is the same as attribute:: . is the same as self::node() .//X is the same as self::node()/descendant-or self::node()/child::X .. is the same as parent::node() // is the same as /descendant-or-self::node()/ //X is the same as /descendant-or-self::node()/child::X October 16, 2019 ICS 541: Xpath

- Arithmetic Expressions + add - subtract * multiply div (not /) divide mod modulo (remainder) October 16, 2019 ICS 541: Xpath

- Equality Tests = “equals” (Notice it’s not ==) != “not equals” But it’s not that simple! value = node-set will be true if the node-set contains any node with a value that matches value value != node-set will be true if the node-set contains any node with a value that does not match value Hence, value = node-set and value != node-set may both be true at the same time! October 16, 2019 ICS 541: Xpath

- Boolean Operators and (infix operator) or (infix operator) Example: count = 0 or count = 1 not() (function) The following are used for numerical comparisons only: < “less than” <= “less than or equal to” > “greater than” >= “greater than or equal to” October 16, 2019 ICS 541: Xpath

- Some XPath Functions XPath contains a number of functions on node sets, numbers, and strings; here are a few of them: count(elem) counts the number of selected elements Example: //chapter[count(section)=2] selects chapters with exactly two section children name() returns the name of the element Example: //*[name()='section'] is the same as //section starts-with(arg1, arg2) tests if arg1 starts with arg2 Example: //*[starts-with(name(), 'sec‘)] contains(arg1, arg2) tests if arg1 contains arg2 Example: //*[contains(name(), 'ect‘)] October 16, 2019 ICS 541: Xpath

- References W3School XPath Tutorial MSXML 4.0 SDK http://www.w3schools.com/xpath/default.asp MSXML 4.0 SDK Several online presentations October 16, 2019 ICS 541: Xpath

- Reading list W3School XPath Tutorial http://www.w3schools.com/xpath/default.asp October 16, 2019 ICS 541: Xpath

END October 16, 2019 ICS 541: Xpath