SlideShare a Scribd company logo
1 of 3
XPath is used to navigate through elements and attributes in an XML document.
XPath is a major element in XSLT standard - and XQuery and XPointer are both
built on XPath expressions
XPath is a language for finding information in an XML document.
• XPath is a syntax for defining parts of an XML document
• XPath uses path expressions to navigate in XML documents
XPath Syntax
XPath uses path expressions to select nodes or node-sets in an XML
document. The node is selected by following a path or steps.
The XML Example Document
We will use the following XML document in the examples below.
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book>
<title lang="eng">Harry Potter</title>
<price>29.99</price>
</book>
<book>
<title lang="eng">Learning XML</title>
<price>39.95</price>
</book>
</bookstore>
Selecting Nodes
XPath uses path expressions to select nodes in an XML document. The node
is selected by following a path or steps. The most useful path expressions
are listed below:
Expression Description
nodename Selects all child nodes of the named node
/ 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 node
@ Selects attributes
In the table below we have listed some path expressions and the result of
the expressions:
Path Expression Result
bookstore Selects all the child nodes of the bookstore element
/bookstore Selects the root element bookstore
Note: If the path starts with a slash ( / ) it always
represents an absolute path to an 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 the
bookstore element, no matter where they are under the
bookstore element
//@lang Selects all attributes that are named lang
Selecting Unknown Nodes
XPath wildcards can be used to select unknown XML elements.
Wildcard Description
* Matches any element node
@* Matches any attribute node
node() Matches any node of any kind
In the table below we have listed some path expressions and the result of
the expressions:
Path Expression Result
/bookstore/* Selects all the child nodes of the bookstore element
//* Selects all elements in the document
//title[@*] Selects all title elements which have any attribute

More Related Content

What's hot (20)

XML and XPath details
XML and XPath detailsXML and XPath details
XML and XPath details
 
XML/XSLT
XML/XSLTXML/XSLT
XML/XSLT
 
Extracting data from xml
Extracting data from xmlExtracting data from xml
Extracting data from xml
 
XSLT presentation
XSLT presentationXSLT presentation
XSLT presentation
 
Session 4
Session 4Session 4
Session 4
 
03 x files
03 x files03 x files
03 x files
 
Rendering XML Document
Rendering XML DocumentRendering XML Document
Rendering XML Document
 
transforming xml using xsl and xslt
transforming xml using xsl and xslttransforming xml using xsl and xslt
transforming xml using xsl and xslt
 
Introductionto xslt
Introductionto xsltIntroductionto xslt
Introductionto xslt
 
Xslt tutorial
Xslt tutorialXslt tutorial
Xslt tutorial
 
Querying XML: XPath and XQuery
Querying XML: XPath and XQueryQuerying XML: XPath and XQuery
Querying XML: XPath and XQuery
 
XSLT
XSLTXSLT
XSLT
 
XML Security Using XSLT
XML Security Using XSLTXML Security Using XSLT
XML Security Using XSLT
 
Xml transformation language
Xml transformation languageXml transformation language
Xml transformation language
 
Intro xml
Intro xmlIntro xml
Intro xml
 
Python xml processing
Python   xml processingPython   xml processing
Python xml processing
 
Web programming xml
Web programming  xmlWeb programming  xml
Web programming xml
 
Xml basics
Xml basicsXml basics
Xml basics
 
00 introduction
00 introduction00 introduction
00 introduction
 
Cs511 data-extraction
Cs511 data-extractionCs511 data-extraction
Cs511 data-extraction
 

Viewers also liked

Feasibility Studies: BTX Manufacturing
Feasibility Studies: BTX ManufacturingFeasibility Studies: BTX Manufacturing
Feasibility Studies: BTX ManufacturingIntratec Solutions
 
The day after the course
The day after the courseThe day after the course
The day after the courseShachar Oz
 
Торгово-офисный центр в Домодедово
Торгово-офисный центр в ДомодедовоТоргово-офисный центр в Домодедово
Торгово-офисный центр в ДомодедовоКонцерн «АйсРоос»
 
Feasibility Studies: Biodiesel Manufacturing
Feasibility Studies: Biodiesel ManufacturingFeasibility Studies: Biodiesel Manufacturing
Feasibility Studies: Biodiesel ManufacturingIntratec Solutions
 
Economics of Bisphenol A Production Processes
Economics of Bisphenol A Production ProcessesEconomics of Bisphenol A Production Processes
Economics of Bisphenol A Production ProcessesIntratec Solutions
 
ANOIKTO PANEPISTIMIO KYPROU Drastiriotita 1
ANOIKTO PANEPISTIMIO KYPROU Drastiriotita 1ANOIKTO PANEPISTIMIO KYPROU Drastiriotita 1
ANOIKTO PANEPISTIMIO KYPROU Drastiriotita 1chrystallacharalampous
 
01 HK RTL - Gesellenbrief dt
01 HK RTL - Gesellenbrief dt01 HK RTL - Gesellenbrief dt
01 HK RTL - Gesellenbrief dtAlexander Pfeffer
 
обоснование нирм
обоснование нирмобоснование нирм
обоснование нирмelena_lagoda
 
OpenCms Days 2013 - Outsourcing OpenCms Template Design
OpenCms Days 2013 - Outsourcing OpenCms Template DesignOpenCms Days 2013 - Outsourcing OpenCms Template Design
OpenCms Days 2013 - Outsourcing OpenCms Template DesignAlkacon Software GmbH & Co. KG
 

Viewers also liked (19)

01 HK RTL - Electrician en
01 HK RTL - Electrician en01 HK RTL - Electrician en
01 HK RTL - Electrician en
 
Feasibility Studies: BTX Manufacturing
Feasibility Studies: BTX ManufacturingFeasibility Studies: BTX Manufacturing
Feasibility Studies: BTX Manufacturing
 
Informatica
InformaticaInformatica
Informatica
 
The day after the course
The day after the courseThe day after the course
The day after the course
 
While.doc
While.docWhile.doc
While.doc
 
Trabajo tecnologia octure 2
Trabajo tecnologia octure 2Trabajo tecnologia octure 2
Trabajo tecnologia octure 2
 
Торгово-офисный центр в Домодедово
Торгово-офисный центр в ДомодедовоТоргово-офисный центр в Домодедово
Торгово-офисный центр в Домодедово
 
Feasibility Studies: Biodiesel Manufacturing
Feasibility Studies: Biodiesel ManufacturingFeasibility Studies: Biodiesel Manufacturing
Feasibility Studies: Biodiesel Manufacturing
 
Economics of Bisphenol A Production Processes
Economics of Bisphenol A Production ProcessesEconomics of Bisphenol A Production Processes
Economics of Bisphenol A Production Processes
 
KING SBC
KING SBCKING SBC
KING SBC
 
Xml material
Xml materialXml material
Xml material
 
Xsd
XsdXsd
Xsd
 
ANOIKTO PANEPISTIMIO KYPROU Drastiriotita 1
ANOIKTO PANEPISTIMIO KYPROU Drastiriotita 1ANOIKTO PANEPISTIMIO KYPROU Drastiriotita 1
ANOIKTO PANEPISTIMIO KYPROU Drastiriotita 1
 
Xsd basics
Xsd basicsXsd basics
Xsd basics
 
01 HK RTL - Gesellenbrief dt
01 HK RTL - Gesellenbrief dt01 HK RTL - Gesellenbrief dt
01 HK RTL - Gesellenbrief dt
 
Presentación1julia
Presentación1juliaPresentación1julia
Presentación1julia
 
X query
X queryX query
X query
 
обоснование нирм
обоснование нирмобоснование нирм
обоснование нирм
 
OpenCms Days 2013 - Outsourcing OpenCms Template Design
OpenCms Days 2013 - Outsourcing OpenCms Template DesignOpenCms Days 2013 - Outsourcing OpenCms Template Design
OpenCms Days 2013 - Outsourcing OpenCms Template Design
 

Similar to XPath Guide - Navigate XML Documents

Similar to XPath Guide - Navigate XML Documents (20)

X path
X pathX path
X path
 
X path
X pathX path
X path
 
TAppWeb Training Material
TAppWeb Training MaterialTAppWeb Training Material
TAppWeb Training Material
 
Xpath.pdf
Xpath.pdfXpath.pdf
Xpath.pdf
 
TAppWeb Training Material
TAppWeb Training MaterialTAppWeb Training Material
TAppWeb Training Material
 
TApp Web training material_rev4
TApp Web training material_rev4TApp Web training material_rev4
TApp Web training material_rev4
 
TApp Documentation
TApp DocumentationTApp Documentation
TApp Documentation
 
Day2 xslt x_path_xquery
Day2 xslt x_path_xqueryDay2 xslt x_path_xquery
Day2 xslt x_path_xquery
 
C:\fakepath\xsl final
C:\fakepath\xsl finalC:\fakepath\xsl final
C:\fakepath\xsl final
 
Xml session
Xml sessionXml session
Xml session
 
Querring xml with xpath
Querring xml with xpath Querring xml with xpath
Querring xml with xpath
 
Learning XSLT
Learning XSLTLearning XSLT
Learning XSLT
 
XPATH_XSLT-1.pptx
XPATH_XSLT-1.pptxXPATH_XSLT-1.pptx
XPATH_XSLT-1.pptx
 
Xml and DTD's
Xml and DTD'sXml and DTD's
Xml and DTD's
 
Xml and Co.
Xml and Co.Xml and Co.
Xml and Co.
 
Week 12 xml and xsl
Week 12 xml and xslWeek 12 xml and xsl
Week 12 xml and xsl
 
Xml
XmlXml
Xml
 
02_Xpath.pdf
02_Xpath.pdf02_Xpath.pdf
02_Xpath.pdf
 
XPath - XML Path Language
XPath - XML Path LanguageXPath - XML Path Language
XPath - XML Path Language
 
Xpath.ppt
Xpath.pptXpath.ppt
Xpath.ppt
 

More from xavier john

Interview questions
Interview questionsInterview questions
Interview questionsxavier john
 
Xavier async callback_fault
Xavier async callback_faultXavier async callback_fault
Xavier async callback_faultxavier john
 
Custom faultpolicies
Custom faultpoliciesCustom faultpolicies
Custom faultpoliciesxavier john
 
All adapterscommonproperties
All adapterscommonpropertiesAll adapterscommonproperties
All adapterscommonpropertiesxavier john
 
Custom faultpolicies
Custom faultpoliciesCustom faultpolicies
Custom faultpoliciesxavier john
 
Oracle business rules
Oracle business rulesOracle business rules
Oracle business rulesxavier john
 
Soa installation
Soa installationSoa installation
Soa installationxavier john
 
All adapterscommonproperties
All adapterscommonpropertiesAll adapterscommonproperties
All adapterscommonpropertiesxavier john
 
All adapterscommonproperties
All adapterscommonpropertiesAll adapterscommonproperties
All adapterscommonpropertiesxavier john
 
oracle soa Examples
oracle soa Examplesoracle soa Examples
oracle soa Examplesxavier john
 
Deployment document
Deployment documentDeployment document
Deployment documentxavier john
 
Database adapter
Database adapterDatabase adapter
Database adapterxavier john
 

More from xavier john (20)

Unix day4 v1.3
Unix day4 v1.3Unix day4 v1.3
Unix day4 v1.3
 
Unix day3 v1.3
Unix day3 v1.3Unix day3 v1.3
Unix day3 v1.3
 
Unix day2 v1.3
Unix day2 v1.3Unix day2 v1.3
Unix day2 v1.3
 
Interview questions
Interview questionsInterview questions
Interview questions
 
Xavier async callback_fault
Xavier async callback_faultXavier async callback_fault
Xavier async callback_fault
 
Custom faultpolicies
Custom faultpoliciesCustom faultpolicies
Custom faultpolicies
 
All adapterscommonproperties
All adapterscommonpropertiesAll adapterscommonproperties
All adapterscommonproperties
 
Custom faultpolicies
Custom faultpoliciesCustom faultpolicies
Custom faultpolicies
 
Oracle business rules
Oracle business rulesOracle business rules
Oracle business rules
 
Soap.doc
Soap.docSoap.doc
Soap.doc
 
Soa installation
Soa installationSoa installation
Soa installation
 
Vx vm
Vx vmVx vm
Vx vm
 
Webservices
WebservicesWebservices
Webservices
 
Xslt
XsltXslt
Xslt
 
All adapterscommonproperties
All adapterscommonpropertiesAll adapterscommonproperties
All adapterscommonproperties
 
All adapterscommonproperties
All adapterscommonpropertiesAll adapterscommonproperties
All adapterscommonproperties
 
Jmsconsume
JmsconsumeJmsconsume
Jmsconsume
 
oracle soa Examples
oracle soa Examplesoracle soa Examples
oracle soa Examples
 
Deployment document
Deployment documentDeployment document
Deployment document
 
Database adapter
Database adapterDatabase adapter
Database adapter
 

Recently uploaded

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 

Recently uploaded (20)

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 

XPath Guide - Navigate XML Documents

  • 1. XPath is used to navigate through elements and attributes in an XML document. XPath is a major element in XSLT standard - and XQuery and XPointer are both built on XPath expressions XPath is a language for finding information in an XML document. • XPath is a syntax for defining parts of an XML document • XPath uses path expressions to navigate in XML documents XPath Syntax XPath uses path expressions to select nodes or node-sets in an XML document. The node is selected by following a path or steps. The XML Example Document We will use the following XML document in the examples below. <?xml version="1.0" encoding="ISO-8859-1"?> <bookstore> <book> <title lang="eng">Harry Potter</title> <price>29.99</price> </book> <book> <title lang="eng">Learning XML</title> <price>39.95</price> </book> </bookstore> Selecting Nodes XPath uses path expressions to select nodes in an XML document. The node is selected by following a path or steps. The most useful path expressions are listed below: Expression Description nodename Selects all child nodes of the named node
  • 2. / 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 node @ Selects attributes In the table below we have listed some path expressions and the result of the expressions: Path Expression Result bookstore Selects all the child nodes of the bookstore element /bookstore Selects the root element bookstore Note: If the path starts with a slash ( / ) it always represents an absolute path to an 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 the bookstore element, no matter where they are under the bookstore element //@lang Selects all attributes that are named lang Selecting Unknown Nodes XPath wildcards can be used to select unknown XML elements. Wildcard Description * Matches any element node @* Matches any attribute node node() Matches any node of any kind In the table below we have listed some path expressions and the result of the expressions: Path Expression Result /bookstore/* Selects all the child nodes of the bookstore element
  • 3. //* Selects all elements in the document //title[@*] Selects all title elements which have any attribute