SlideShare a Scribd company logo
1 of 27
XPath - XML Path Language  XML http://yht4ever.blogspot.com [email_address] B070066 - NIIT Quang Trung 08/2007
Contents Exercises Node-set Operators and Functions Location Paths Nodes Introduction
Introduction ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Nodes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Simple XML document  1 <?xml version =  &quot;1.0&quot; ?> 2 3 <!-- simple.xml --> 4 <!-- Simple XML document  --> 5 6 <book title =  “C++ How to Program&quot;   edition =  &quot;3&quot; > 7 8   <sample> 9   <![CDATA[ 10   11   // C++ comment 12   if ( this->getX() < 5 && value[ 0 ] != 3 ) 13   cerr << this->displayError(); 14   ]]> 15   </sample> 16   17   C++ How to Program by Deitel &amp; Deitel 18 </book> Root node Comment nodes Attribute nodes Element nodes Text nodes
XPath tree for simple.xml Attribute Title C++ How to Program Element book Comment Fig. 11.1 : simple.xml Comment Simple XML document Attribute edition 3 Root Text C++ How to Program by Deitel & Deitel Element sample Text // C++ comment  if (this -> getX() < 5 && value[ 0 ] != 3 )    cerr << this->displayError();
XML document with processing-instruction and namespace nodes 1 <?xml version =  &quot;1.0&quot; ?> 2 3 <!-- Fig. 11.3 : simple2.xml  --> 4 <!-- Processing instructions and namespacess  --> 5 6 <html xmlns =  &quot;http://www.w3.org/TR/REC-html40&quot; > 7 8   <head> 9   <title> Processing Instruction and Namespace Nodes </title> 10   </head> 11 12   <?deitelprocessor example =  &quot;fig11_03.xml&quot; ?> 13 14   <body> 15 16   <deitel:book deitel:edition =  &quot;1&quot;   17   xmlns:deitel =  &quot;http://www.deitel.com/xmlhtp1&quot; > 18   <deitel:title> XML How to Program </deitel:title> 19   </deitel:book> 20 21   </body> 22 23 </html> Root node Comment nodes Namespace nodes Processing instruction node Element nodes Text nodes Attribute nodes
Tree diagram of an XML document with a processing-instruction node Continued on next slide ... Root Comment Fig. 11.3 : simple2.xml Comment Processing instructions and namespaces Element html Namespace http://www.w3.org/TR/REC-html40 Element head Text Processing instructions and Namespcae Nodes Element title
Tree diagram of an XML document with a processing-instruction node Continued from previous slide Processing Instruction deitelprocessor example =  &quot; fig11_03.xml &quot; Element body Element book Attribute edition 1 Namespace http://www.deitel.com/xmlhtp1 Element title Text XML How to Program
XPath node types
XPath node types (cont.)
Location Paths ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Axes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
XPath axes
Node Tests ,[object Object],[object Object],[object Object],[object Object]
Some XPath node tests
Location Paths Using Axes and Node Tests ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Some location-path abbreviations
Node-set Operators and Functions ,[object Object],[object Object],[object Object],[object Object]
Node-set operators
Some node-set functions
Node-set Operators and Functions (cont.) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
1 <?xml version =  &quot;1.0&quot; ?> 2 3 <!-- Fig. 11.13 : stocks.xml --> 4 <!-- Stock list  --> 5 6 <stocks> 7 8   <stock symbol =  &quot;INTC&quot; > 9   <name> Intel Corporation </name> 10   </stock> 11 12   <stock symbol =  &quot;CSCO&quot; > 13   <name> Cisco Systems, Inc. </name> 14   </stock> 15 16   <stock symbol =  &quot;DELL&quot; > 17   <name> Dell Computer Corporation </name> 18   </stock> 19 20   <stock symbol =  &quot;MSFT&quot; > 21   <name> Microsoft Corporation </name> 22   </stock> 23 24   <stock symbol =  &quot;SUNW&quot; > 25   <name> Sun Microsystems, Inc. </name> 26   </stock> 27 28   <stock symbol =   &quot;CMGI&quot; > 29   <name> CMGI, Inc. </name> 30   </stock> 31 32 </stocks>
1 <?xml version =  &quot;1.0&quot; ?> 2 3 <!-- Fig. 11.14 : stocks.xsl --> 4 <!-- string function usage  --> 5 6 <xsl:stylesheet version =  &quot;1.0&quot; 7   xmlns:xsl =  &quot;http://www.w3.org/1999/XSL/Transform&quot; > 8 9   <xsl:template match =  &quot;/stocks&quot; > 10   <html> 11   <body> 12   <ul> 13 14   <xsl:for-each select =  &quot;stock&quot; > 15 16   <xsl:if test =  17   &quot;starts-with(@symbol, 'C')&quot; > 18 19   <li> 20   <xsl:value-of select =  21   &quot;concat(@symbol,' - ', name)&quot; /> 22   </li> 23   </xsl:if> 24 25   </xsl:for-each> 26   </ul> 27   </body> 28   </html> 29   </xsl:template> 30 </xsl:stylesheet> XPath string functions
Reference ,[object Object],[object Object],[object Object]
Q&A ,[object Object],[object Object]
http://yht4ever.blogspot.com Thank You !

More Related Content

What's hot

1. introduction to html5
1. introduction to html51. introduction to html5
1. introduction to html5
JayjZens
 

What's hot (20)

Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
 
Use of Lists and Tables in HTML
Use of Lists and Tables in HTMLUse of Lists and Tables in HTML
Use of Lists and Tables in HTML
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
HTML Semantic Tags
HTML Semantic TagsHTML Semantic Tags
HTML Semantic Tags
 
Css Ppt
Css PptCss Ppt
Css Ppt
 
JCR, Sling or AEM? Which API should I use and when?
JCR, Sling or AEM? Which API should I use and when?JCR, Sling or AEM? Which API should I use and when?
JCR, Sling or AEM? Which API should I use and when?
 
Basics of React Hooks.pptx.pdf
Basics of React Hooks.pptx.pdfBasics of React Hooks.pptx.pdf
Basics of React Hooks.pptx.pdf
 
Xml 215-presentation
Xml 215-presentationXml 215-presentation
Xml 215-presentation
 
Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
 
Html5 semantics
Html5 semanticsHtml5 semantics
Html5 semantics
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
XPATH
XPATHXPATH
XPATH
 
XML
XMLXML
XML
 
Html 5
Html 5Html 5
Html 5
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
Integration patterns in AEM 6
Integration patterns in AEM 6Integration patterns in AEM 6
Integration patterns in AEM 6
 
Javascript essentials
Javascript essentialsJavascript essentials
Javascript essentials
 
1. introduction to html5
1. introduction to html51. introduction to html5
1. introduction to html5
 

Viewers also liked

eXtensible Markup Language
eXtensible Markup LanguageeXtensible Markup Language
eXtensible Markup Language
Aditya Raj
 
Overview of XSL, XPath and XSL-FO
Overview of XSL, XPath and XSL-FOOverview of XSL, XPath and XSL-FO
Overview of XSL, XPath and XSL-FO
Suite Solutions
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
chomas kandar
 
Querying XML: XPath and XQuery
Querying XML: XPath and XQueryQuerying XML: XPath and XQuery
Querying XML: XPath and XQuery
Katrien Verbert
 

Viewers also liked (20)

XML
XMLXML
XML
 
XMPP - Introduction And LAS Implementation (Presentation)
XMPP - Introduction And LAS  Implementation (Presentation)XMPP - Introduction And LAS  Implementation (Presentation)
XMPP - Introduction And LAS Implementation (Presentation)
 
Introduction
IntroductionIntroduction
Introduction
 
IEEE 2014 JAVA DATA MINING PROJECTS Xs path navigation on xml schemas made easy
IEEE 2014 JAVA DATA MINING PROJECTS Xs path navigation on xml schemas made easyIEEE 2014 JAVA DATA MINING PROJECTS Xs path navigation on xml schemas made easy
IEEE 2014 JAVA DATA MINING PROJECTS Xs path navigation on xml schemas made easy
 
eXtensible Markup Language
eXtensible Markup LanguageeXtensible Markup Language
eXtensible Markup Language
 
Xs path navigation on xml schemas made easy
Xs path navigation on xml schemas made easy Xs path navigation on xml schemas made easy
Xs path navigation on xml schemas made easy
 
XML and XPath details
XML and XPath detailsXML and XPath details
XML and XPath details
 
Introduction to XPath
Introduction to XPathIntroduction to XPath
Introduction to XPath
 
Understanding XML DOM
Understanding XML DOMUnderstanding XML DOM
Understanding XML DOM
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
XSLT
XSLTXSLT
XSLT
 
Overview of XSL, XPath and XSL-FO
Overview of XSL, XPath and XSL-FOOverview of XSL, XPath and XSL-FO
Overview of XSL, XPath and XSL-FO
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
Xml dom
Xml domXml dom
Xml dom
 
Web Scraping for Code-ophobes
Web Scraping for Code-ophobesWeb Scraping for Code-ophobes
Web Scraping for Code-ophobes
 
XSLT
XSLTXSLT
XSLT
 
An Introduction to the DOM
An Introduction to the DOMAn Introduction to the DOM
An Introduction to the DOM
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
SEO Hacks & Apps
SEO Hacks & AppsSEO Hacks & Apps
SEO Hacks & Apps
 
Querying XML: XPath and XQuery
Querying XML: XPath and XQueryQuerying XML: XPath and XQuery
Querying XML: XPath and XQuery
 

Similar to XPath - XML Path Language

Similar to XPath - XML Path Language (20)

Processing XML with Java
Processing XML with JavaProcessing XML with Java
Processing XML with Java
 
6 311 W
6 311 W6 311 W
6 311 W
 
6 311 W
6 311 W6 311 W
6 311 W
 
test
testtest
test
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Inroduction to XSLT with PHP4
Inroduction to XSLT with PHP4Inroduction to XSLT with PHP4
Inroduction to XSLT with PHP4
 
Struts2
Struts2Struts2
Struts2
 
Sax Dom Tutorial
Sax Dom TutorialSax Dom Tutorial
Sax Dom Tutorial
 
Csphtp1 18
Csphtp1 18Csphtp1 18
Csphtp1 18
 
Xml
XmlXml
Xml
 
Relax NG, a Schema Language for XML
Relax NG, a Schema Language for XMLRelax NG, a Schema Language for XML
Relax NG, a Schema Language for XML
 
Lotusphere 2006 AD212 Introduction to DXL
Lotusphere 2006 AD212 Introduction to DXLLotusphere 2006 AD212 Introduction to DXL
Lotusphere 2006 AD212 Introduction to DXL
 
XML Transformations With PHP
XML Transformations With PHPXML Transformations With PHP
XML Transformations With PHP
 
Xml and Co.
Xml and Co.Xml and Co.
Xml and Co.
 
Wso2 Scenarios Esb Webinar July 1st
Wso2 Scenarios Esb Webinar July 1stWso2 Scenarios Esb Webinar July 1st
Wso2 Scenarios Esb Webinar July 1st
 
AdvancedXPath
AdvancedXPathAdvancedXPath
AdvancedXPath
 
Combinators, DSLs, HTML and F#
Combinators, DSLs, HTML and F#Combinators, DSLs, HTML and F#
Combinators, DSLs, HTML and F#
 
Java XML Parsing
Java XML ParsingJava XML Parsing
Java XML Parsing
 
Unit 5 xml (1)
Unit 5   xml (1)Unit 5   xml (1)
Unit 5 xml (1)
 
Xml session
Xml sessionXml session
Xml session
 

More from yht4ever (12)

Applications of SOA and Web Services in Grid Computing
Applications of SOA and Web Services in Grid ComputingApplications of SOA and Web Services in Grid Computing
Applications of SOA and Web Services in Grid Computing
 
ERD - Database Design
ERD - Database DesignERD - Database Design
ERD - Database Design
 
Web Page Authoring 1
Web Page Authoring 1Web Page Authoring 1
Web Page Authoring 1
 
Introduction to HTML
Introduction to HTMLIntroduction to HTML
Introduction to HTML
 
Introduction to HTML
Introduction to HTMLIntroduction to HTML
Introduction to HTML
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
Rendering XML Document
Rendering XML DocumentRendering XML Document
Rendering XML Document
 
Rendering XML Documents
Rendering XML DocumentsRendering XML Documents
Rendering XML Documents
 
XML Schema
XML SchemaXML Schema
XML Schema
 
Document Type Definition
Document Type DefinitionDocument Type Definition
Document Type Definition
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
GUI Programming In Java
GUI Programming In JavaGUI Programming In Java
GUI Programming In Java
 

Recently uploaded

Recently uploaded (20)

MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

XPath - XML Path Language

  • 1. XPath - XML Path Language XML http://yht4ever.blogspot.com [email_address] B070066 - NIIT Quang Trung 08/2007
  • 2. Contents Exercises Node-set Operators and Functions Location Paths Nodes Introduction
  • 3.
  • 4.
  • 5. Simple XML document 1 <?xml version = &quot;1.0&quot; ?> 2 3 <!-- simple.xml --> 4 <!-- Simple XML document --> 5 6 <book title = “C++ How to Program&quot; edition = &quot;3&quot; > 7 8 <sample> 9 <![CDATA[ 10 11 // C++ comment 12 if ( this->getX() < 5 && value[ 0 ] != 3 ) 13 cerr << this->displayError(); 14 ]]> 15 </sample> 16 17 C++ How to Program by Deitel &amp; Deitel 18 </book> Root node Comment nodes Attribute nodes Element nodes Text nodes
  • 6. XPath tree for simple.xml Attribute Title C++ How to Program Element book Comment Fig. 11.1 : simple.xml Comment Simple XML document Attribute edition 3 Root Text C++ How to Program by Deitel & Deitel Element sample Text // C++ comment if (this -> getX() < 5 && value[ 0 ] != 3 ) cerr << this->displayError();
  • 7. XML document with processing-instruction and namespace nodes 1 <?xml version = &quot;1.0&quot; ?> 2 3 <!-- Fig. 11.3 : simple2.xml --> 4 <!-- Processing instructions and namespacess --> 5 6 <html xmlns = &quot;http://www.w3.org/TR/REC-html40&quot; > 7 8 <head> 9 <title> Processing Instruction and Namespace Nodes </title> 10 </head> 11 12 <?deitelprocessor example = &quot;fig11_03.xml&quot; ?> 13 14 <body> 15 16 <deitel:book deitel:edition = &quot;1&quot; 17 xmlns:deitel = &quot;http://www.deitel.com/xmlhtp1&quot; > 18 <deitel:title> XML How to Program </deitel:title> 19 </deitel:book> 20 21 </body> 22 23 </html> Root node Comment nodes Namespace nodes Processing instruction node Element nodes Text nodes Attribute nodes
  • 8. Tree diagram of an XML document with a processing-instruction node Continued on next slide ... Root Comment Fig. 11.3 : simple2.xml Comment Processing instructions and namespaces Element html Namespace http://www.w3.org/TR/REC-html40 Element head Text Processing instructions and Namespcae Nodes Element title
  • 9. Tree diagram of an XML document with a processing-instruction node Continued from previous slide Processing Instruction deitelprocessor example = &quot; fig11_03.xml &quot; Element body Element book Attribute edition 1 Namespace http://www.deitel.com/xmlhtp1 Element title Text XML How to Program
  • 11. XPath node types (cont.)
  • 12.
  • 13.
  • 15.
  • 17.
  • 19.
  • 22.
  • 23. 1 <?xml version = &quot;1.0&quot; ?> 2 3 <!-- Fig. 11.13 : stocks.xml --> 4 <!-- Stock list --> 5 6 <stocks> 7 8 <stock symbol = &quot;INTC&quot; > 9 <name> Intel Corporation </name> 10 </stock> 11 12 <stock symbol = &quot;CSCO&quot; > 13 <name> Cisco Systems, Inc. </name> 14 </stock> 15 16 <stock symbol = &quot;DELL&quot; > 17 <name> Dell Computer Corporation </name> 18 </stock> 19 20 <stock symbol = &quot;MSFT&quot; > 21 <name> Microsoft Corporation </name> 22 </stock> 23 24 <stock symbol = &quot;SUNW&quot; > 25 <name> Sun Microsystems, Inc. </name> 26 </stock> 27 28 <stock symbol = &quot;CMGI&quot; > 29 <name> CMGI, Inc. </name> 30 </stock> 31 32 </stocks>
  • 24. 1 <?xml version = &quot;1.0&quot; ?> 2 3 <!-- Fig. 11.14 : stocks.xsl --> 4 <!-- string function usage --> 5 6 <xsl:stylesheet version = &quot;1.0&quot; 7 xmlns:xsl = &quot;http://www.w3.org/1999/XSL/Transform&quot; > 8 9 <xsl:template match = &quot;/stocks&quot; > 10 <html> 11 <body> 12 <ul> 13 14 <xsl:for-each select = &quot;stock&quot; > 15 16 <xsl:if test = 17 &quot;starts-with(@symbol, 'C')&quot; > 18 19 <li> 20 <xsl:value-of select = 21 &quot;concat(@symbol,' - ', name)&quot; /> 22 </li> 23 </xsl:if> 24 25 </xsl:for-each> 26 </ul> 27 </body> 28 </html> 29 </xsl:template> 30 </xsl:stylesheet> XPath string functions
  • 25.
  • 26.