Welcome   |   ASP.NET   |   Web Services   |   How Do I...?   |   Class Browser
  |   I want my samples in...   

How Do I...? Common Tasks QuickStart Tutorial

Go To...

How Do I...Process XML Data Using XPath?

This sample illustrates how to process XML data using the XPathNavigator class. An XPathDocument object is used to load the XML document, and to return an XPathNavigator object. The XPathNavigator object is then used to create a compiled XPath expression in an XPathExpression object. The selection methods of the XPathNavigator object then select XML data using the compiled XPath expression. Finally, the navigation methods of the XPathNavigator and XmlDocument classes are used to navigate the XML data in the XML document.

C# XPathWithXPathDoc.exe
View Source

[This sample can be found at M:\web\users\Sites\AspnetQuickStart\v2.0\QuickStart\howto\samples\Xml\BinaryDataInXml\
To build this sample, open the SDK command prompt and navigate to the above path. Build the sample using the build tool msbuild passing the solution file as the first parameter: msbuild mySample.sln. The compiled executable will be found in the sub directory \bin directory.]

The following code creates the XPathDocument object and loads the XML document.

		
XPathDocument xPathDocument = new XPathDocument(document);
C#

The following code returns an XPathNavigator object from the XPathDocument object.

		
XPathNavigator xPathNavigator = xPathDocument.CreateNavigator();
C#

The following code creates a compiled XPath expression in an XPathExpression object using the XPathNavigator object.

		
xPathExpr = xPathNavigator.Compile(selectExpr);
C#

The following code selects XML data using the compiled XPath expression.

		
XPathNodeIterator xPathNodeIterator = xPathNavigator.Select(xPathExpr);
C#



Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2005 Microsoft Corporation. All rights reserved.


Hosted by MaximumASP | Found a broken link? | Contact Us | Terms and conditions | Privacy Policy | Advertise with us
� 2000 - 2008  Mindcracker LLC. All Rights Reserved