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

Command line arguments.21
Command line arguments.21Command line arguments.21
Command line arguments.21
myrajendra
 
TypeScript Presentation
TypeScript PresentationTypeScript Presentation
TypeScript Presentation
Patrick John Pacaña
 

What's hot (20)

Xml
XmlXml
Xml
 
Javascript
JavascriptJavascript
Javascript
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
Html for beginners
Html for beginnersHtml for beginners
Html for beginners
 
Bootstrap
BootstrapBootstrap
Bootstrap
 
PL/SQL Fundamentals I
PL/SQL Fundamentals IPL/SQL Fundamentals I
PL/SQL Fundamentals I
 
Java: Objects and Object References
Java: Objects and Object ReferencesJava: Objects and Object References
Java: Objects and Object References
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
 
Command line arguments.21
Command line arguments.21Command line arguments.21
Command line arguments.21
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
 
Basic html
Basic htmlBasic html
Basic html
 
Scripting robot
Scripting robotScripting robot
Scripting robot
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the pain
 
TypeScript - An Introduction
TypeScript - An IntroductionTypeScript - An Introduction
TypeScript - An Introduction
 
Html
HtmlHtml
Html
 
XML Schema
XML SchemaXML Schema
XML Schema
 
An Introduction to the DOM
An Introduction to the DOMAn Introduction to the DOM
An Introduction to the DOM
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
Jquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsJquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript Basics
 
TypeScript Presentation
TypeScript PresentationTypeScript Presentation
TypeScript Presentation
 

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
 
XPATH
XPATHXPATH
XPATH
 
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 (11)

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
 
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

Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
UK Journal
 

Recently uploaded (20)

Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptx
BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptxBT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptx
BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptx
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 

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.