IHasXmlNode Interface
Collapse the table of content
Expand the table of content

IHasXmlNode Interface


Enables a class to return an XmlNode from the current context or position.

Namespace:   System.Xml
Assembly:  System.Xml (in System.Xml.dll)

public interface IHasXmlNode


Returns the XmlNode for the current position.

The IHasXmlNode interface provides an interface that enables a class to return an XmlNode from the current context or position. It is implemented by XPathNavigator objects that operate over classes that have XmlNode nodes. For example, if the XPathNavigator object is created by an XmlDocument, you can use the GetNode method to return the XmlNode representing the current position of the navigator.

The following example uses the GetNode method to retrieve and modify the selected node.

using System;
using System.IO;
using System.Xml;
using System.Xml.XPath;

public class Sample
  public static void Main()
     XmlDocument doc = new XmlDocument();

     // Create an XPathNavigator and select all books by Plato.
     XPathNavigator nav = doc.CreateNavigator();
     XPathNodeIterator ni = nav.Select("descendant::book[author/name='Plato']");

     // Get the first matching node and change the book price.
     XmlNode book = ((IHasXmlNode)ni.Current).GetNode();
     book.LastChild.InnerText = "12.95";


The example uses the file books.xml as input.

.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft