

Listing 6-32 Moves though an entire document and displays the data on the console. Now, using the MoveToNext and MoveToParent methods, you can move through the entire document. ' Create XPathNavigator object by calling CreateNavigator of XmlDocumentĬonsole.WriteLine( "Base URI" & ())Ĭonsole.WriteLine( "Name:" & ())Ĭonsole.WriteLine( "Node Type: " & ())Ĭonsole.WriteLine( "Node Value: " & ()) Moving to root and first child nodes using XpathNavigator Once you have a root, you can display corresponding information such as name, value, node type, and so on. Listing 6-31 uses the MoveToRoot and MoveToFirstChild methods to move to the root node and first child of the root node. So, with the help of these methods, you can move through a document as a DOM tree. Some of these methods are MoveToFirst, moveToNext, MoveToroot, MoveToFirstAttribute, MoveToFirstChild, MoveToId, MoveToNamespace, MoveToPrevious, MoveToParent and so on. Table 6-8 describes the XPathNavigator class's move methods. XPathNavigator contain methods and properties to move to the first, next, child, parent, and root nodes to the document. XPath to your project before using any of its classes. Note: Don't forget to add a reference of the System.Xml. ' Create XPathNavigator object by calling create Navigator of XmlDocumentĭim nav As XPathNavigator = xmlDoc.CreateNavigator()
#XMLMIND W2X NEXT PREVIOUS NAVIGATION CODE#
For example, the following code calls XmlDocument's CreateNavigator method to create a XPathNavigator object:

You can also create a XPathNavigator object by calling XmlDocument's CreateNavigator method. You create an XPathNavigator instance by calling XPpathDocument's CreateNavigator method. It has easy-to-use and self-explanatory methods. The XPathNavigator class implements the functionality to navigate through a document. You can pass an XmlReader, TextReader, or even direct XML filenames. You use the XPathDocument constructor to create an instance of XmlPathDocument. The XPathDocument class provides a fast cache for XML document processing using XSLT and XPath. XPathExpression provides selection criteria to select a set of nodes from a document based on those criteria, and the XPathExection class is an exception class. The XPathNodeIterator class provides iteration capabilities to a node. XPathNodeIterator, XPathExpression, and XPathException are other classes defined in this namespace. Before using these classes, you must add a reference of the namespace to your application. The XPath namespace contains classes to provide read-only, fast access to documents. The namespace defines both these classes. These classes are XPathDocument and XPathNavigator.

As you've seen, XmlNode provides a way to navigate DOM tree with the help of its FirstChild, ChildNodes, LastChild, PreviousNode, NextSibling, and PreviousSibling methods.īesides XmlNode, the XML.NET has two more classes, which help you navigate XML documents.
