Home   |   QuickStart Welcome   |   ASP.NET   |   Web Services   |   How Do I...?   
  |   I want my samples in...      

How Do I...? Common Tasks QuickStart Tutorial

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.

VB XPathWithXPathDoc.exe
View Source
[This sample can be found at C:\DevFusion.Data\legacy\quickstart.developerfusion.co.uk\QuickStart\howto\samples\Xml\BinaryDataInXml\]

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

		
XPathDocument myXPathDocument = new XPathDocument(args);
C#

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

		
XPathNavigator myXPathNavigator = myXPathDocument.CreateNavigator();
C#

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

		
myXPathExpr = myXPathNavigator.Compile(selectExpr);
C#

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

		
XPathNodeIterator myXPathNodeIterator = myXPathNavigator.Select(myXPathExpr);
C#



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