XML
  Home arrow XML arrow Page 2 - Introduction to XPath
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

Introduction to XPath
By: Mamun Zaman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2007-08-15

    Table of Contents:
  • Introduction to XPath
  • Path Expression Syntax
  • Getting Elements
  • Using XPath

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Introduction to XPath - Path Expression Syntax


    (Page 2 of 4 )

    The basic path expression syntax is similar in style to file-system addressing. If the path starts with the slash ( / ), then it represents an absolute path to the required element. Only the / represents the root element. For the example above, the expression "/" represents <bookstore>. To get all the <book> elements use: 

    /book

    This will return both <book> elements. To get the <price> elements use:

     /book/price

    <bookstore>
     
    <book>
       
    <title id='1'>XPath Tutorial</title>
       
    <author>Mamun Zaman</author>
       
    <year>2007</year>
       
    <price>00.99</price>
      
    </book>
      <book>
       
    <title id='2'>AJAX Tutorial</title>
       
    <author>Charles</author>
       
    <year>2007</year>
       
    <price>03.45</price>
     
    </book>
    </bookstore>

    If the path starts with // then all elements in the document which fulfill the following criteria are selected. The //B expression selects all <B> tags regardless of their parents.

    <root>
              <B/>
              <C/>
              <B/>
              <D>
                   <B/>
              </D>
              <C>
                   <D>
                        <B/>
                        <B/>
                   </D>
              </C>
    </root>

    The star * selects all elements located by the preceding path. To select all elements under <book> use the /book/* path expression.

    <bookstore>
     
    <book>
       
    <title id='1'>XPath Tutorial</title>
       
    <author>Mamun Zaman</author>
       
    <year>2007</year>
       
    <price>00.99</price>
     
    </book>
     
    <book>
       
    <title id='2'>AJAX Tutorial</title>
       
    <author>Charles</author>
        
    <year>2007</year>
       
    <price>03.45</price>
     
    </book>
    </bookstore>

    More XML Articles
    More By Mamun Zaman


     

    XML ARTICLES

    - Path, Predicates, and XQuery
    - Using Predicates with XQuery
    - Navigating Input Documents Using Paths
    - XML Basics
    - Introduction to XPath
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE
    - UI Design with Java and XML Toolkits
    - Displaying ADO Retrieved Data with XML Islan...
    - Widget Walkthrough
    - Introduction to Widgets
    - The Why and How of XML Data Islands
    - Creating an XUL App Installer
    - Overlays in XUL
    - Skinning Your Custom XUL Applications







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway