IHasXmlNode and XPathNavigator

Reading the docs on IHasXmlNode I assumed an XPathNavigator object would always implement IHasXmlNode.  The examples always use CreateNavigator() on an XmlDocument object.  I assumed this was just an example.

If I use CreateNavigator() on an XPathDocument object, that XPathNavigator object does not implement IHasXmlNode.  For example:


XmlTextReader reader = new XmlTextReader(@"file.xml");
XPathDocument document = new XPathDocument(reader);
XPathNavigator navigator = document.CreateNavigator();
IHasXmlNode inode = navigator as IHasXmlNode;

 
inode is now null.  Have I made an incorrect assumption




Answer this question

IHasXmlNode and XPathNavigator

  • Doooode

    XPathDocument is not editable and is not implemented using XmlNodes, which is why it does not support IHasXmlNode interface.  If you need XmlNode objects, use XmlDocument instead.
  • IHasXmlNode and XPathNavigator