What is the difference between XPathNavigator and XmlDocument?

It seems to be similar methods.

  • one
    @Ev_Hyper So go for it. Translate the answers, get the reputation. then you search, add, there will be a Klondike in general. - Vadim Ovchinnikov
  • @VadimOvchinnikov, thanks, but no. Because to write a normal answer will take more time than the one that I now have. - Ev_Hyper

1 answer 1

Generally speaking, XmlDocument provides an object-oriented XML processing method, while XPathNavigator provides a cursor-oriented method of operation.

In practice, the difference is that XPathNavigator is simpler and faster, but XmlDocument more flexible. For example, if you need to create a new XML document, then you will have to use an XmlDocument , since an XPathNavigator (more correctly, an XPathDocument ) requires an already created document.

It is recommended to use the XPathDocument and XPathNavigator classes when working with very large XML documents due to the fact that they are slightly faster. In all other cases, XmlDocument looks preferable.

  • Ie XPathDocument does not load the entire document into memory? - iluxa1810
  • And another question, but what is the difference from XmlReader then? He also seems to be like a cursor and reads everything consistently. - iluxa1810
  • Not quite like this: it will load the load (but I will not say 100%, I did not watch the source code), but it will be done ( referencesource.microsoft.com/#system.xml/System/Xml/XPath/… ) and fewer calls will be activated than when loading an XmlDocument. - SeNS
  • XmlReader (see referencesource.microsoft.com/#system.xml/System/Xml/Core/… ) is a class of abstraction level lower than XPathDocument, that is, it is even easier and faster, but the level of service provided is lower. - SeNS
  • I apologize, in the first comment the phrase "did not look at the sources" should be crossed out. Because of the strange editing policy of ru.so, I can't make corrections :( Yes, and you can and should watch the source code! - SeNS