Working with XPath: The .NET Way - XPath related classes in .NET
(Page 4 of 5 )
.NET framework provides full support to XML with the “System.XML” namespace. If we need to work with XPath, the following classes would be a bit helpful:
- XPathNavigator
- XPathNodeIterator
- XPathExpression
- XPathDocument
- XPathException
The “XPathNavigator” class allows you to define a read-only, random access cursor on a data store. The “XPathNodeIterator” class enables you to iterate a set of nodes that you select by calling an XPath method. The “XPathExpression” class encapsulates a compiled XPath expression. An XPathExpression object is returned when you call the Compile method. The Select, Evaluate, and Matches methods use this class. The “XPathDocument” class provides a read-only cache for fast and highly optimized processing of XML documents using XSLT. “XPathException” is the exception that is thrown when an error occurs during the processing of an XPath expression.
Apart from the above, there exists one more interface, “IXPathNavigable”. This interface enables you to create an XPathNavigator class. The classes that implement this interface enable you to create navigators using the CreateNavigator method.
To create an XPathNavigator object for an XML document, you use the CreateNavigator method of the XmlNode and XPathDocument classes, which implements the IXPathNavigable interface. The CreateNavigator method returns an XPathNavigator object. You can then use the XPathNavigator object to perform XPath queries. You can use XPathNavigator to select a set of nodes from any data store that implements the IXPathNavigable interface. A data store is the source of data, which may be a file, a database, an XmlDocument object, or a DataSet object. You can also create your own implementation of the XPathNavigator class that can query other data stores.
The XPathNavigator object reads data from an XML document by using a cursor that enables forward and backward navigation within the nodes. In addition, XPathNavigator provides random access to nodes. However, because the cursor that the XPathNavigator object uses is read-only, you cannot edit an XML document by using the XPathNavigator object.
Next: Examining XPath with a simple VB.NET/C# example >>
More .NET Articles
More By Jagadish Chaterjee