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.

Slides:



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

Dr. Alexandra I. Cristea XPath and Namespaces.
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.
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)
1 Before The Class What’re the roles of us in this subject? –A researcher –A developer –A problem solver –IT related technologies What’s really confused.
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.
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.
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"
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
17 Apr 2002 XML Stylesheets Andy Clark. What Is It? Extensible Stylesheet Language (XSL) Language for document transformation – Transformation (XSLT)
Manohar – Why XML is Required Problem: We want to save the data and retrieve it further or to transfer over the network. This.
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
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.
1/17 ITApplications XML Module Session 7: Introduction to XPath.
IS432 Semi-Structured Data Lecture 5: XSLT Dr. Gamal Al-Shorbagy.
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.
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.
XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000.
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.
1 Displaying XML Document Web and Database Management System.
More on XSLT 07. More on XSLT © Aptech Limited XPath  In this first lesson, XPath, you will learn to:  Define and describe XPath.  Identify nodes according.
IS432: Semi-Structured Data Dr. Azeddine Chikh. 6. XML Path (XPath)
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.
[ Part III of The XML seminar ] Presenter: Xiaogeng Zhao A Introduction of XQL.
XPath Presented by Kushan Athukorala. 2 Agenda XPath XPath Terminology Selecting Nodes Predicates.
1 XML Data Management XPath Principles Werner Nutt.
Submitted To: Ms. Poonam Saini, Asst. Prof., NITTTR Submitted By: Rohit Handa ME (Modular) CSE 2011 Batch.
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.
IS432 Semi-Structured Data Lecture 4: XPath Dr. Gamal Al-Shorbagy.
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.
Displaying Data with XSLT ©NIITeXtensible Markup Language/Lesson 6/Slide 1 of 45 Objectives In this lesson, you will learn to: * Perform conditional formatting.
5 Copyright © 2004, Oracle. All rights reserved. Navigating XML Documents by Using XPath.
CH 15 XSL Transformations 1. Objective What is XSL? Overview of XSL transformations Understanding XSL templates Computing the value of a node with xsl:value-of.
XML. What is XML? XML stands for EXtensible Markup Language XML is a markup language much like HTML XML was designed to carry data, not to display data.
XML Query languages--XPath. Objectives Understand XPath, and be able to use XPath expressions to find fragments of an XML document Understand tree patterns,
Beginning XML 4th Edition.
XML and XPath.
Xpath creation.
{ XML Technologies } BY: DR. M’HAMED MATAOUI
XML Path Language Andy Clark 17 Apr 2002.
XPath 9-May-19.
XML DOCUMENTS & DATABASES
Xpath October 16, 2019 ICS 541: Xpath.
XPath 7-Dec-19.
Presentation transcript:

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 An XML document is a tree made up of nodes. XPath is a language for picking nodes and sets of nodes out of this tree using path expressions/location paths. An XPath expression returns either a node-set, a string, a Boolean, or a number.

XPath is a major component in the XSLT standard. XSL are XML-based Stylesheet Language. XPath became a W3C Recommendation 16. November XPath includes over 100 built-in functions. There are functions for String values, Numeric values, Boolean values, Date and Time comparison, Node manipulation and more. N O X SLT WITHOUT XP ATH !!

XP ATH N ODES XML documents are treated as trees of nodes. The topmost element of the tree is called the root element. In XPath, there are seven kinds of nodes: I. Root nodes II. Element nodes III. Attribute nodes IV. Text nodes V. Namespace nodes VI. Processing-instruction nodes VII. Comment nodes.

E XAMPLE : XP ATH N ODES Harry Potter J K. Rowling (root element node) J K. Rowling (element node) J K. Rowling (text node) lang="en" (attribute node) (processing-instruction node) (comment node) (namespace node) XML DocNodes

R ELATIONSHIP OF N ODES Nodes in an XML are related in the following way by XPath: Parent Each element/attribute has one parent. Children Element nodes may have 0, 1 or more children. Siblings Nodes that have the same parent. Ancestors A node's parent, parent's parent, etc. Descendants A node's children, children's children, etc.

Harry Potter J K. Rowling In the above example; book - parent of the title, author, year, and price. title, author, year and price - children of book element. title, author, year and price - siblings. book, bookstore element - ancestors of title element. book, title, author etc. elements - descendants of bookstore. E XAMPLE : XP ATH N ODES

XP ATH – L OCATION P ATHS Location Path are the Path Expressions. XPath uses Location Paths to select nodes or node-sets in an XML document. Expression / Location Path Description nodename Selects all nodes with the name "nodename" / Selects from the root node // Selects nodes in the document from the current node that match the selection no matter where they are. Selects the current node.. Selects the parent of the current Selects attributes

A location path can be absolute or relative. An absolute location path starts with a slash ( / ) /step/step/... and a relative location path does not. step/step/... The XPath expressions such as element name, /, comment( ), text( ), and processing-instruction( ) are all Single Location Paths/Steps. Location Paths can be combined with “ / ” to move around the hierarchy from the matched node to other nodes. Such Location Paths are called Compound Location Paths. Ex: /people/person/name/first_name. The above compound location XPath expression lists the first name of all the persons listed inside the people element. XP ATH – L OCATION P ATHS

XP ATH : S ELECTING N ODES Harry Potter Learning XML Path ExpressionResult bookstore Selects all nodes with the name "bookstore" /bookstore Selects the root element bookstore/book Selects all book elements that are children of bookstore //book Selects all book elements no matter where they are in the document bookstore//book Selects all book elements that are descendant of bookstore. Selects all attributes that are named lang

N ODE T ESTS – M ORE L OCATION P ATHS Having covered element, attribute and root nodes above, the rest 4 kinds of nodes i.e. namespace, text, processing-instruction and comment nodes can also be selected as below: Node TestDescription comment() Selects nodes that are comments. node() Selects nodes of any type. processing- instruction() Selects nodes that are processing instructions. You can specify which processing instruction to select by providing it's name in the parentheses. text() Selects a text node.

XP ATH : P REDICATES Predicates (embedded in square brackets) are used to find a specific node or a node that contains a specific value. Path ExpressionResult /bookstore/book[1] Selects first book element that is child of bookstore element /bookstore/book[last()] Selects last book element that is child of the bookstore /bookstore/book[last()-1] Selects last but one book element that is child of bookstore /bookstore/book [position()<3] Selects first 2 book elements that are children of bookstore Selects all title elements that have an attribute named lang Selects all title elements having "lang" attribute with “en” value /bookstore/book [price>35.00] Selects all the book elements of the bookstore element that have a price element with a value greater than /bookstore/book [price>35.00]/title Selects all the title elements of book elements of bookstore element having price with a value greater than 35.00

XP ATH : W ILDCARDS XPath wildcards can be used to select unknown XML elements. Example: WildcardDescription * Matches any element Matches any attribute node node() Matches any node of any kind Path ExpressionResult /bookstore/* Selects all child element nodes of bookstore element //* Selects all elements in the document Selects all title elements having at least 1 attribute

C OMPLEX XP ATH E XAMPLES : WITH WILD-CARDS, NODE TESTS, PREDICATES Path ExpressionResult bookstore/*/title All elements that are grandchildren of elements. /bookstore/book[1]/title Select the title of the first book /bookstore/book/price[text()] Selects the text from all price nodes //Participant [string-length(FirstName)>=8] Return all Participant nodes with a contents of FirstName bigger than 7 characters: /bookstore/book[price>35]/title Select title nodes with price>35 The style attribute for all elements of current context. books//book[contains(title, 'XQuery')]/title/text() Get all the books that contain the word 'XQuery" somewhere in the title

XP ATH : S EVERAL P ATHS By using the | operator in an XPath expression you can select several paths. Example: Path ExpressionResult //book/title | //book/price Selects all the title AND price elements of all book elements //title | //price Selects all the title AND price elements in the document /bookstore/book/title | //price Selects all the title elements of the book element of the bookstore element AND all the price elements in the document

XP ATH O PERATORS OperatorDescriptionExample | Computes two node-sets//book | //cd + Additionemployee/id[6+ 4] - Subtractionemployee/id[6 – 4] * Multiplication//age[6 * 4] div Division//age[8 div 4] = != Not equal//item[price!=9.80] < Less than//item[price<9.80] <= Less than or equal to//item[price <= 2] > Greater than//exercise[note>5]/title >= Greater than or equal to//item[price>=9.80] or //item[price=9.80 or price=9.70] and //item[price>9.00 and price<9.90] mod Modulus (division remainder)//item/title[id > 5 mod 2]

XP ATH R ETURN T YPES Each XPath function returns one of these four types: Boolean, Number, Node-set, String. Types Example Boolean most commonly used in predicates of location paths. Example: person[profession="physicist"], profession="physicist" is a Boolean. Strings XPath strings are ordered sequences of Unicode characters such as "Fred", " ", or "". You can use the = and != comparison operators to check whether two strings are the same and relational, = operators to compare strings. Number XPath provides the five basic arithmetic operators : +, -, *, div, mod which can be used on numbers. Example: 1900 mod 100]] Node-set Set of nodes as a result of path expression.

XP ATH F UNCTIONS ON N ODE -S ETS NameDescription name(nodeset) Returns the name of the current node or the first node in the specified node set. root(node) Returns root of the tree to which the current node or the specified belongs. This will usually be a document node. count((item) Returns the count of nodes. Example : count[//person] position() Returns the index position of the node that is currently being processed. Example: //book[position()<=3] Result: Selects the first three book elements last() Returns the number of items in the processed node list. Example: //book[last()] Result: Selects the last book element

XP ATH F UNCTIONS ON S TRING NameDescription string(arg) Returns the string value of the argument. The argument could be a number, boolean, or node-set. Example: string(314) Result: "314" compare(comp1,comp2) Returns -1 if comp1 is less than comp2, 0 if comp1 is equal to comp2, or 1 if comp1 is greater than comp2. Example: compare('ghi', 'ghi') Result: 0 concat(string,string,...) Returns the concatenation of the strings. Example: concat('XPath ','is ','FUN!') Result: 'XPath is FUN!' string-length(string) Returns the length of the specified string. Example: string-length('Beatles') Result: 7

upper-case(string) Converts string argument to upper-case. Example: upper-case('The XML') Result: 'THE XML' lower-case(string) Converts the string argument to lower- case. Example: lower-case('The XML') Result: 'the xml' starts- with(string1,string2) Returns true if string1 starts with string2, otherwise it returns false. Example: starts-with('XML','X') Result: true ends- with(string1,string2) Returns true if string1 ends with string2, otherwise it returns false. Example: ends-with('XML','X') Result: false tokenize(string,pattern) Example: tokenize("XPath is fun", "\s+") Result: ("XPath", "is", "fun") XP ATH F UNCTIONS ON S TRING

substring- before(string1,string2) Returns the start of string1 before string2 occurs in it. Example: substring-before('12/10','/') Result: '12' substring- after(string1,string2) Returns the remainder of string1 after string2 occurs in it. Example: substring-after('12/10','/') Result: '10' matches(string,pattern) Returns true if the string argument matches the pattern, otherwise, it returns false. Example: matches("Merano", "ran") Result: true replace(string, pattern,replace) Returns a string created by replacing the given pattern with given argument. Example: replace("Bella Italia", "l", "*") Result: 'Be**a Ita*ia' XP ATH F UNCTIONS ON S TRING

Contains (string1,string2) Returns true if string1 contains string2, otherwise returns false. Example: contains('XML','XM') Result: true Substring (string,start,len) substring (string,start) Returns the substring from the start position to specified length. If length is omitted it returns the substring from the start position to the end. Example: substring('Beatles',1,4) Result: 'Beat' normalize- space(string) Removes leading and trailing spaces from the string, and replaces all internal sequences of white space with one and returns the result. Example: normalize-space(' The XML ') Result: 'The XML' XP ATH F UNCTIONS ON S TRING

XP ATH F UNCTIONS ON N UMERIC V ALUES NameDescription number(arg) Returns numeric value of the argument. Arg. could be Boolean, string, or node-set. Example: number('100') -> Result: 100 abs(num) Returns the absolute value of argument. Example: abs(-3.14) -> Result: 3.14 ceiling(num) Returns the smallest integer that is greater than the number argument. Example: ceiling(3.14) -> Result: 4 floor(num) Returns the largest integer that is not greater than the number argument Example: floor(3.14) -> Result: 3 round(num) Rounds the number to nearest integer. Example: round(3.14) -> Result: 3 sum(arg,arg,...) Returns the sum of the numeric value of each node in the specified node-set.

XP ATH F UNCTIONS ON B OOLEAN V ALUES NameDescription boolean(arg) Returns a boolean value for a number, string, or node-set. not(arg) Returns true if the boolean value is false, and false if the boolean value is true. Example: not(true()) Result: false true() Returns the boolean value true. Example: true() Result: true false() Returns the boolean value false. Example: false() Result: false

Thank you !