1 / 20

Chapter 11 – XML Path Language (XPath)

Chapter 11 – XML Path Language (XPath). Outline 11.1 Introduction 11.2 Nodes 11.3 Location Paths 11.3.1 Axes 11.3.2 Node Tests 11.3.3 Location Paths Using Axes and Node Tests 11.4 Node-set Operators and Functions 11.5 Internet and World Wide Web Resources. 1 <?xml version = "1.0" ?>.

tawana
Download Presentation

Chapter 11 – XML Path Language (XPath)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 11 – XML Path Language (XPath) Outline11.1 Introduction11.2 Nodes11.3 Location Paths 11.3.1 Axes 11.3.2 Node Tests 11.3.3 Location Paths Using Axes and Node Tests11.4 Node-set Operators and Functions11.5 Internet and World Wide Web Resources

  2. 1 <?xml version = "1.0"?> 2 3 <!-- Fig. 11.1 : simple.xml --> 4 <!-- Simple XML document --> 5 6 <book title = "C++ How to Program"edition = "3"> 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> Fig. 11.1 Simple XML document.

  3. Root CommentFig. 11.1 : simple.xml CommentSimple XML document Elementbook AttributeTitleC++ How to Program Attributeedition 3 Elementsample Text// C++ comment if (this -> getX() < 5 && value[ 0 ] != 3 ) cerr << this->displayError(); TextC++ How to Program by Deitel & Deitel Fig. 11.2 XPath tree for Fig. 11.1.

  4. 1 <?xml version = "1.0"?> 2 3 <!-- Fig. 11.3 : simple2.xml --> 4 <!-- Processing instructions and namespacess --> 5 6 <html xmlns = "http://www.w3.org/TR/REC-html40"> 7 8 <head> 9 <title>Processing Instruction and Namespace Nodes</title> 10 </head> 11 12 <?deitelprocessor example = "fig11_03.xml"?> 13 14 <body> 15 16 <deitel:book deitel:edition = "1" 17 xmlns:deitel = "http://www.deitel.com/xmlhtp1"> 18 <deitel:title>XML How to Program</deitel:title> 19 </deitel:book> 20 21 </body> 22 23 </html> Fig. 11.3 XML document with processing-instruction and namespace nodes.

  5. Root CommentFig. 11.3 : simple2.xml CommentProcessing instructions and namespaces Elementhtml Namespacehttp://www.w3.org/TR/REC-html40 Elementhead Elementtitle TextProcessing instructions and Namespcae Nodes Continued… Fig. 11.4 Tree diagram of an XML documentwith a processing-instruction node

  6. …Continued Processing Instructiondeitelprocessorexample = “fig11_03.xml” Elementbody Elementbook Attributeedition1 Namespacehttp://www.deitel.com/xmlhtp1 Elementtitle TextXML Hot to Program Fig. 11.4 Tree diagram of an XML document with a processing-instruction node. (Part 2)

  7. Fig. 11.5 XPath node types

  8. Fig. 11.5 XPath node types. (Part 2)

  9. Fig. 11.6 XPath axes.

  10. Fig. 11.7 Some XPath node tests.

  11. Fig. 11.8 Some location-path abbreviations.

  12. 1 <?xml version = "1.0"?> 2 3 <!-- Fig. 11.9 : books.xml --> 4 <!-- XML book list --> 5 6 <books> 7 8 <book> 9 <title>Java How to Program</title> 10 <translation edition = "1">Spanish</translation> 11 <translation edition = "1">Chinese</translation> 12 <translation edition = "1">Japanese</translation> 13 <translation edition = "2">French</translation> 14 <translation edition = "2">Japanese</translation> 15 </book> 16 17 <book> 18 <title>C++ How to Program</title> 19 <translation edition = "1">Korean</translation> 20 <translation edition = "2">French</translation> 21 <translation edition = "2">Spanish</translation> 22 <translation edition = "3">Italian</translation> 23 <translation edition = "3">Japanese</translation> 24 </book> 25 26 </books> Fig. 11.9 XML document that marks up book translations.

  13. Output for Fig. 11.9

  14. Othernodes… ElementBOOK Elementtitle TextJava How to Program Attributeedition 1 Elementtranslation TextSpanish Attributeedition 1 Elementtranslation TextChinese Attributeedition 1 Elementtranslation TextJapanese Continued… Fig. 11.10 XPath tree for books.xml

  15. Continued… Elementtranslation Attributeedition 2 TextFrench Elementtranslation Attributeedition 2 TextJapanese Othernodes… Fig. 11.10 XPath tree for books.xml

  16. Fig. 11.11 Node-set operators.

  17. Fig. 11.12 Some node-set functions.

  18. 1 <?xml version = "1.0"?> 2 3 <!-- Fig. 11.13 : stocks.xml --> 4 <!-- Stock list --> 5 6 <stocks> 7 8 <stock symbol = "INTC"> 9 <name>Intel Corporation</name> 10 </stock> 11 12 <stock symbol = "CSCO"> 13 <name>Cisco Systems, Inc.</name> 14 </stock> 15 16 <stock symbol = "DELL"> 17 <name>Dell Computer Corporation</name> 18 </stock> 19 20 <stock symbol = "MSFT"> 21 <name>Microsoft Corporation</name> 22 </stock> 23 24 <stock symbol = "SUNW"> 25 <name>Sun Microsystems, Inc.</name> 26 </stock> 27 28 <stock symbol ="CMGI"> 29 <name>CMGI, Inc.</name> 30 </stock> 31 32 </stocks> Fig. 11.13 List of companies with stock symbols.

  19. 1 <?xml version = "1.0"?> 2 3 <!-- Fig. 11.14 : stocks.xsl --> 4 <!-- string function usage --> 5 6 <xsl:stylesheet version = "1.0" 7 xmlns:xsl = "http://www.w3.org/1999/XSL/Transform"> 8 9 <xsl:template match = "/stocks"> 10 <html> 11 <body> 12 <ul> 13 14 <xsl:for-each select = "stock"> 15 16 <xsl:if test = 17 "starts-with(@symbol, 'C')"> 18 19 <li> 20 <xsl:value-of select = 21 "concat(@symbol,' - ', name)"/> 22 </li> 23 </xsl:if> 24 25 </xsl:for-each> 26 </ul> 27 </body> 28 </html> 29 </xsl:template> 30 </xsl:stylesheet> Fig. 11.14 Demonstrating some String functions.

  20. Output for Fig. 11.14

More Related