This tutorial will show you how to navigate XML information items in ASP.NET 2.0 using C#.

First, import the namespace of System.XML and System.XML.XPath

The System.Xml.XPath namespace contains the classes that define a cursor model for navigating and editing XML information items as instances of the XPath 2.0 Data Model. In this sample, we will use the classes of XPathDocument, XPathNavigator, XPathExpression and XPathNodeIterator under this namespace.

The Button1_Click event is to perform the navgating XML infomration items fuction. The results will be displayed in the textbox. There are 4 classes we applied.

  • XPathDocument: Provides a fast, read-only, in-memory representation of an XML document using the XPath data model.
  • XPathNavigator: Provides a cursor model for navigating XML data.
  • XPathExpression: Provides a typed class that represents a compiled XPath expression.
  • XPathNodeIterator: Provides an iterator over a selected set of nodes.

The contents of Demo.xml:

The front end Default.aspx page looks something like this:

The flow for the code behind page as follows.

Download Source Files