Managing Data Exchange: 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.
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.
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.
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.
XML –Query Languages, Extracting from Relational Databases ADVANCED DATABASES Khawaja Mohiuddin Assistant Professor Department of Computer Sciences Bahria.
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
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.
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.
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.
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.
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.
Li Tak Sing COMPS311F. XPath XPath is a simple language that allows you to write expressions to refer to different parts of an XML document. We will learn.
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.
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.
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.
XSLT: How Do We Use It? Nancy Hallberg Nikki Massaro Kauffman.
1 XPath. 2 Agenda XPath Introduction XPath Nodes XPath Syntax XPath Operators XPath Q&A.
XSLT I Robin Burke ECT 360. Outline History / Terminology XSLT processing XSLT syntax XPath XSLT basics Lab.
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.
XML Path Language Andy Clark 17 Apr 2002.
XPath 9-May-19.
More XML XML schema, XPATH, XSLT
Xpath October 16, 2019 ICS 541: Xpath.
XPath 7-Dec-19.
Presentation transcript:

Managing Data Exchange: XPath Presented By: David Harris

Chapter Objectives: Conceptualize an XML document as a node tree Understand the differences between Abbreviated and Unabbreviated syntax Understand the differences between Absolute vs. Relative Paths Use of predicates and functions

XPath Overview: XML path language is used for referring to “nodes” in an XML document The node relationships are parent, child, descendent, sibling and ancestor A node precedes another node if it comes first in document order A node follows another node if it comes after it in the document order

XML and HTML as tree structures:

XML as a tree structure: Trunk = Root Element BigBranch = Parent

XPath Axes Examples: Axes Meaning ancestor:: Parents of the current node upto the root node ancestor-or-self:: Parents of the current node upto the root node and the current node attribute:: Attributes of the current node child:: Immediate children of the current node descendant:: Children of the current node (including children's children) descendant-or-self:: Children of the current node (including children's children) and the current node following:: Nodes after the current node (excluding children) following-sibling:: Nodes after the current node (excluding children) at the same level namespace:: XML namespace of the current node parent:: Immediate parent of the current node preceding:: Nodes before the current node (excluding children) preceding-sibling:: Nodes before the current node (excluding children) at the same level self:: The current node

Unabbreviated Syntax: <?xml version="1.0" encoding="UTF-8"?> <trunk name="the_trunk"> <bigBranch name="bb1" thickness="thick"> <smallBranch name="sb1"> <leaf name="leaf1" color="brown" /> <leaf name="leaf2" weight="50" /> <leaf name="leaf3" /> </smallBranch> <smallBranch name="sb2"> <leaf name="leaf4" weight="90" /> <leaf name="leaf5" color="purple" /> </smallBranch> </bigBranch> <bigBranch name="bb2"> <smallBranch name="sb3"> <leaf name="leaf6" /> <smallBranch name="sb4"> <leaf name="leaf7" /> <leaf name="leaf8" /> <leaf name="leaf9" color="black" /> <leaf name="leaf10" weight="100" /> </smallBranch> </trunk> 1. All <leaf> elements in this document that are children of <smallBranch> elements that are children of <bigBranch> elements, that are children of the trunk, which is the child of the root. Syntax: /child::trunk/child::bigBranch/child::smallBranch/child::leaf -The two colons between are called an axis 2. The <bigBranch> elements with “name” attribute equal to “bb2”, that are the children of the trunk element, which is the child of the root. /child::trunk/child::bigBranch[attribute::name=‘bb2’] -The predicate is in the square brackets -Predicate here is asking for the big branch node with attribute name set to “bb2”. -attribute must be spelled out and include the axis.

Abbreviated Syntax: <?xml version="1.0" encoding="UTF-8"?> <trunk name="the_trunk"> <bigBranch name="bb1" thickness="thick"> <smallBranch name="sb1"> <leaf name="leaf1" color="brown" /> <leaf name="leaf2" weight="50" /> <leaf name="leaf3" /> </smallBranch> <smallBranch name="sb2"> <leaf name="leaf4" weight="90" /> <leaf name="leaf5" color="purple" /> </smallBranch> </bigBranch> <bigBranch name="bb2"> <smallBranch name="sb3"> <leaf name="leaf6" /> <smallBranch name="sb4"> <leaf name="leaf7" /> <leaf name="leaf8" /> <leaf name="leaf9" color="black" /> <leaf name="leaf10" weight="100" /> </smallBranch> </trunk> 1. All <leaf> elements in this document that are children of <smallBranch> elements that are children of <bigBranch> elements, that are children of the trunk, which is the child of the root. Syntax: /trunk/bigBranch/smallBranch/leaf 2. The <bigBranch> elements with “name” attribute equal to “bb2”, that are the children of the trunk element, which is the child of the root. /trunk/bigBranch[@name=‘bb2’] -The predicate is in the square brackets -Predicate here is asking for the big branch node with attribute name set to “bb2”. -”attribute” is replaced with the @ symbol

Relative vs. Absolute Paths Works much like when referring to other files in HTML hyperlinks by including things such as server name, folders, and file names Relative Path: Gives the file location in relation to the current working directory. Directories and sub-directories are separated by a slash ‘ / ‘, but do not begin with one. Absolute Path: Gives an exact location of a file or directory name within a computer or file system. Begins with a slash ‘ / ‘ and directories and sub-directories are separated by a slash ‘ / ‘.

Relative and Absolute Paths <?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> <!-- Example of an absolute link. The element ‘/child::trunk'’ is being specified from the root element. --> <xsl:template match="/child::trunk"> <html> <head> <title>XPath Tree Tests</title> </head> <body> <!-- Example of a relative link. The <for-each> xsl statement will execute for every <bigBranch> node in the ‘current’ node, which is the <trunk>node. --> <xsl:for-each select="child::bigBranch"> <xsl:call-template name="print_out" /> </xsl:for-each> </body> </html> </xsl:template> <xsl:template name="print_out"> <xsl:value-of select="attribute::name" /> <br /> </xsl:stylesheet>

Four Types of XPath Location Paths The combining of Relative, Absolute, Abbreviated, and Unabbreviated creates four possible location paths. 1. Abbreviated Relative Location Paths 2. Abbreviated Absolute Location Paths 3. Unabbreviated Relative Location Paths 4. Unabbreviated Absolute Location Paths

Movie Examples: <?XML Version=“1.0” encoding=“”?> <movieList> <movie> <movieName>Wedding Crashers</movieName> <movieLength>120</movieLength> <movieRating>PG-13</movieRating> </movie> <movieName>Dodge Ball</movieName> <movieLength>105</movieLength> <movieName>Spider Man</movieName> <movieLength>132</movieLength> <movieRating>R</movieRating> </movieList> -The following XPath expression will be used to select certain elements from the movieList. 1. Show all the movie names on the movie list. /movieList/movie/movieName 2. Select all the movies that have a length greater than 115 minutes. /movieList/movie/[movieLength >115]

Predicates and Functions Predicates allow for further filtering of selections Predicates get evaluated in each set of nodes Examples: 1. number last() = last node in the current node set number 2. number position() = position of the context node being tested 3. number count(node-set) = the number of nodes in a node set 4. number sum(node-set) = the number of numeric values of the nodes in the node-set 5. number round(number) = the number, rounded to the nearest integer

Predicate and Functions Examples: <?XML Version=“1.0” encoding=“UTF-8”?> <movieList> <movie> <movieName>Wedding Crashers</movieName> <movieLength>120</movieLength> <movieRating>PG-13</movieRating> </movie> <movieName>Dodge Ball</movieName> <movieLength>105</movieLength> <movieName>Spider Man</movieName> <movieLength>132</movieLength> <movieRating>R</movieRating> </movieList> 1. If you would like to get the last node the function would look like this: /movieList/movie/[last()] -It is possible to select more than one path. When doing this the ( | ) operator is used. 2. Select the movie name and how long it last. /movieList/movie/movieName | /movieList/movie/movieLength

Questions?

Exercises: Modify a previous document and stylesheet of your choice, or create a new one, so that your stylesheet uses a predicate to call for a specific item in your document. Also incorporate the use of a function of your choice in a stylesheet.