Modified Slides from Dr. Sagiv

Slides:



Advertisements
Similar presentations
Dr. Alexandra I. Cristea CS 253: Topics in Database Systems: XPath, NameSpaces.
Advertisements

XPATH מבוא MCSD Doron Amir What is XPath? A W3C Standard A W3C Standard Not written in XML Not written in XML Defines parts of an XML.
XML, XML Schema, Xpath and XQuery Slides collated from various sources, many from Dan Suciu at Univ. of Washington.
1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
Managing Data Exchange: XPath
+ XSL eXtensible Stylesheet Language. + 2 XML Lecture Adapted from the work of Prof Mark Baker ACET, University of Reading.
The learning site: /xpath_syntax.asp xsl/xsl/slides.html.
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.
Multi Platform Applications XML, XPath, XSLT transform.
1 XSL – XML Stylesheet Language. 2 XSL XSL = XML Stylesheet Language XSL cosists of –XPath (navigation in documents) –XSLT (T for transformations) –XSLFO.
1 Extensible Stylesheet Language (XSL) Extensible Stylesheet Language (XSL)
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 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.
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.
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
CIS 375—Web App Dev II XPath. 2 XPath IntroductionIntroduction What is XPath? XPath is a syntax for defining parts of an _____ document XPath uses paths.
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.
CSE3201/CSE4500 XPath. 2 XPath A locator for elements or attributes in an XML document. XPath expression gives direction.
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.
1 cs XSL XSL is a standard that consists of three parts: XPath (navigation in documents) XPath was taught in the DB course, so it will not be.
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.
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.
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.
1 Overview of XSL. 2 Outline We will use Roger Costello’s tutorial The purpose of this presentation is  To give a quick overview of XSL  To describe.
WPI, MOHAMED ELTABAKH PROCESSING AND QUERYING XML 1.
XPath Presented by Kushan Athukorala. 2 Agenda XPath XPath Terminology Selecting Nodes Predicates.
1 cs XSL XSL is a standard that consists of three parts: XPath (navigation in documents) XPath was taught in the DB course, so it will not be.
1 XML Data Management Extracting Data from XML: XPath Werner Nutt based on slides by Sara Cohen, Jerusalem.
Session II Chapter 3 – Chapter 3 – XPath Patterns & Expressions Chapter 4 – XPath Functions Chapter 15 – XPath 2.0http://
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.
1 The XPath Language. 2 XPath Expressions Flexible notation for navigating around trees A basic technology that is widely used uniqueness and scope in.
1 XPath Extracting Data from XML. 2 Data stored in an XML document must be extracted to use with various applications Data can be extracted programmatically.
1 Extensible Stylesheet Language (XSL) Extensible Stylesheet Language (XSL)
CITA 330 Section 5 XPath. XSL XSL (Extensible Stylesheet Language) is the standard language for writing stylesheets to transform XML documents among different.
1 XSL Transformations (XSLT). 2 XSLT XSLT is a language for transforming XML documents into XHTML documents or to other XML documents. XSLT uses XPath.
1 Extensible Stylesheet Language (XSL) Extensible Stylesheet Language (XSL)
XML – eXtensible Markup Language. The World Wide Web and What We Would Like to Do with It XML has a lot of hype surrounding it This week we discuss: –Why.
XML and XPath.
Querying and Transforming XML Data
Extensible Stylesheet Language (XSL)
Lecture XSLT.
{ XML Technologies } BY: DR. M’HAMED MATAOUI
XML Path Language Andy Clark 17 Apr 2002.
Modified Slides from Dr. Sagiv
XPath 9-May-19.
XML DOCUMENTS & DATABASES
Xpath October 16, 2019 ICS 541: Xpath.
XPath 7-Dec-19.
Presentation transcript:

Modified Slides from Dr. Sagiv XPATH Modified Slides from Dr. Sagiv

XPath A Language for Locating Nodes in XML Documents XPath expressions are written in a syntax that resembles paths in file systems The list of nodes located by an XPath expression is called a Nodelist XPath is used in XSL and in XQuery (a query language for XML) W3Schools has an XPath tutorial XPath includes Axis navigation Conditions Functions

<?xml version="1.0" encoding="ISO-8859-1"?> <catalog> <cd country="UK"> <title>Dark Side of the Moon</title> <artist>Pink Floyd</artist> <price>10.90</price> </cd> <title>Space Oddity</title> <artist>David Bowie</artist> <price>9.90</price> <cd country="USA"> <title>Aretha: Lady Soul</title> <artist>Aretha Franklin</artist> </catalog> An XML document

catalog.xml catalog cd cd cd title artist price title artist price country cd country country USA UK UK title artist price title artist price title artist price Space Oddity Aretha: Lady Soul Dark Side of the Moon David Bowie Aretha Franklin Pink Floyd 10.90 9.90 9.90

The Main Idea in the Syntax of XPath Expressoins “/” at the beginning of an XPath expression represents the root of the document “/” between element names represents a parent-child relationship “//” represents an ancestor-descendent relationship “@” marks an attribute “[condition]” specifies a condition

Getting the root element of the document catalog.xml catalog /catalog cd cd country cd country country USA UK UK title artist price title artist price title artist price Space Oddity Aretha: Lady Soul Dark Side of the Moon David Bowie Aretha Franklin Pink Floyd 10.90 9.90 9.90 Getting the root element of the document

catalog.xml catalog /catalog/cd cd cd cd title artist price title country cd country country USA UK UK title artist price title artist price title artist price Space Oddity Aretha: Lady Soul Dark Side of the Moon David Bowie Aretha Franklin Pink Floyd 10.90 9.90 9.90 Finding child nodes

Finding descendent nodes catalog.xml catalog /catalog/cd/price cd cd country cd country country USA UK UK title artist price title artist price title artist price Space Oddity Aretha: Lady Soul Dark Side of the Moon David Bowie Aretha Franklin Pink Floyd 10.90 9.90 9.90 Finding descendent nodes

/catalog/cd[price<10] catalog.xml catalog /catalog/cd[price<10] cd cd country cd country country USA UK UK title artist price title artist price title artist price Space Oddity Aretha: Lady Soul Dark Side of the Moon David Bowie Aretha Franklin Pink Floyd 10.90 9.90 9.90 Condition on elements

// represents any directed path in the document catalog.xml /catalog//title catalog //title cd cd country cd country country USA UK UK title artist price title artist price title artist price Space Oddity Aretha: Lady Soul Dark Side of the Moon David Bowie Aretha Franklin Pink Floyd 10.90 9.90 9.90 // represents any directed path in the document

* represents any element name in the document catalog.xml catalog /catalog/cd/* cd cd country cd country country USA UK UK title artist price title artist price title artist price Space Oddity Aretha: Lady Soul Dark Side of the Moon David Bowie Aretha Franklin Pink Floyd 10.90 9.90 9.90 * represents any element name in the document

* represents any element name in the document /*/* catalog.xml What will the following expressions return? //* catalog //*[price=9.90] //*[price=9.90]/* cd cd country cd country country USA UK UK title artist price title artist price title artist price Space Oddity Aretha: Lady Soul Dark Side of the Moon David Bowie Aretha Franklin Pink Floyd 10.90 9.90 9.90 * represents any element name in the document

Position based condition catalog.xml /catalog/cd[1] catalog /catalog/cd[last()] cd cd country cd country country USA UK UK title artist price title artist price title artist price Space Oddity Aretha: Lady Soul Dark Side of the Moon David Bowie Aretha Franklin Pink Floyd 10.90 9.90 9.90 Position based condition

catalog.xml catalog cd cd cd title artist price title artist price /catalog/cd[@country=“UK”] catalog cd cd country cd country country USA UK UK title artist price title artist price title artist price Space Oddity Aretha: Lady Soul Dark Side of the Moon David Bowie Aretha Franklin Pink Floyd 10.90 9.90 9.90 @ marks attributes

catalog.xml catalog cd cd cd title artist price title artist price /catalog/cd/@country cd cd country cd country country USA UK UK title artist price title artist price title artist price Space Oddity Aretha: Lady Soul Dark Side of the Moon David Bowie Aretha Franklin Pink Floyd 10.90 9.90 9.90 @ marks attributes

Relative Navigation Using Axes Starts with the current node and not with the root (/) A . marks the current node (e.g., ./title) A .. marks the parent node (e.g., title/../*) There are also other axes, e.g., child, descendent, ancestor, parent, following-sibling, etc.

Functions Many functions that are included in XPath Some examples: count() – returns the number of nodes in a nodelist last() – returns the last node in a nodelist name() – returns the name of a node position() – returns the position of the node in the nodelist

Additional Examples of XPath Expressions These examples use element names that are not necessarily from the XML document that was shown previously

Examples of XPath Expressions para Selects the para children elements of the context node * Selects all element children of the context node text() Selects all text node children of the context node @name Selects the name attribute of the context node

More Examples of XPath Expressions @* Selects all the attributes of the context node para[1] Selects the first para child of the context node para[last()] Selects the last para child of the context node */para Selects all para grandchilren of the context node

More Examples of XPath Expressions /doc/chapter[5]/section[2] Selects the second section of the fifth chapter of the doc chapter//para Selects the para element descendants of the chapter element children 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

More Examples of XPath Expressions //olist/item Selects all the item elements that have an olist parent and are in the same document as the context node . Selects the context node .//para Selects the para descendants of the context node .. Selects the parent of the context node

More Examples of XPath Expressions ../@lang Selects the lang attribute of the parent of the context node para[@type=“warning”] Selects the para children of the context node that have a type attribute with value warning chapter[title] Selects the chapter children of the context node that have one or more title children

More Examples of XPath Expressions para[@type=“warning”][5] Selects the fifth para child among the children of the context node that have a type attribute with value warning para[5][@type=“warning”] Selects the fifth para child of the context node if that child has a type attribute with value warning

More Examples of XPath Expressions chapter[title=“Introduction”] Selects the chapter children of the context node that have one or more title children with string-value equal to Introduction employee[@secretary and @assistant] Selects employee children of the context node that have both a secretary attribute and an assistant attribute

More Examples of Xpath Expressions /university/department/course This Xpath expression matches any path that starts at the root, which is a university element, passes through a department element and ends in a course element ./department/course[@year=2002] This Xpath expression matches any path that starts at the current element, continues to a child which is a department element and ends at a course element with a year attribute that is equal to 2002

Location Paths The previous examples are abbreviations of location paths See XPath tutorial in W3Schools For example, // is short for /descendant-or-self::node()/. //para is short for /descendant-or-self::node()/child::para