.NET
  Home arrow .NET arrow Page 3 - Working with XPath: The .NET Way
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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? 
.NET

Working with XPath: The .NET Way
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 30
    2005-11-01

    Table of Contents:
  • Working with XPath: The .NET Way
  • What is inside XPath?
  • XPath with a simple example
  • XPath related classes in .NET
  • Examining XPath with a simple VB.NET/C# example

  • 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


    Working with XPath: The .NET Way - XPath with a simple example


    (Page 3 of 5 )

    The XPath type system is very simple, as you can observe from the following:

    • Node-set (A collection of nodes without duplicates)
    • Boolean (true or false)
    • Number (integers or floating point numbers)
    • String (sequence of characters)

    Let us consider a small XML document (invoice.xml) containing the following information:

    <invoice id=’123’>
           <item>
               <sku>100</sku>
               <price>9.95</price>
           </item>
           <item>
               <sku>101</sku>
               <price>29.95</price>
           </item>
    </invoice>

    The hierarchy would start with “root” (just consider “/”) and then only continues with “invoice” (and further with item, sku, price and so on). The following XPath expression identifies the two “price” elements:

    /invoice/item/price

    The above type of expression is called a “location path”.  Location path expressions look like file system paths, only they navigate through the XPath tree model to identify a set of nodes (known as a node-set).  A location path expression yields a node-set.  Location paths can be absolute or relative.  Absolute location paths begin with a forward slash (/) whereas relative location paths do not.

    XPath can be used with a variety of XML processors including MSXML DOM, .NET, JAXP and so on.  The following is a simple JavaScript (based on MSXML DOM) to search for elements in an XML document using XPath:

    var nl = doc.selectNodes(“/invoice/item/price”);
    for (i=0;i<nl.length;i++)
    {
    //do some processing here
    }

    More .NET Articles
    More By Jagadish Chaterjee


       · get in touch with XPath now. any doubts...do not hesitate to post them
       · Simple and easy explaination of the concepts.
       · This is a very Good article for beginners.
       · Great example ... I am trying the following and having no luck. Was wondering...
       · Sorry I should mention that the record count returned of 100 is when you change the...
     

    .NET ARTICLES

    - Building Applications with Windows Workflow ...
    - Building the Data and Business Layers Using ...
    - The Transformed XML Explorer in MFC
    - List Control and Property Grid with the MFC ...
    - Font, Shell and Masked Edit Controls for MFC
    - Color, Link and Image Editor Controls for M...
    - New Controls for MFC
    - The Windows Ribbon Framework
    - Markup Language for the Ribbon Framework
    - Visually Upgrade Your MFC Project
    - New Features for the Statusbar in MFC
    - Working with the Statusbar in MFC
    - Iron Speed Design v60 Review
    - Binary and XML Serialization
    - Using CrystalReportViewer to Display Crystal...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek