In other words, is XMLDocument more efficient than XmlReader to validate a well formed xml document? from a memory prospective if you have a large XML file and used XMLDocument you might end with out of memory exception.
XMLDocument VS XmlReader which is more efficient to validate well-formed XML in C#
303 views Asked by Ahmed Moheb At
2
There are 2 answers
2
On
To expand on your answer a bit, it depends on what you are trying to do. If this is truly just validating, then XmlDocument is probably the correct version, as it has to complete load to validate. The reader is a "firehose cursor" of sorts that streams the data as you read it. When you have a reader, reading to end will validate. May be a bit faster, but a bit more code.
That is the answer I was looking for it was provided in a comment by @canton7 XmlReader is a low-level streaming API. XmlDocument is a higher-level API built on top of XmlReader. Using the level which is appropriate: maybe you want an easier-to-use convenient API, or maybe you want to write lots of code to use the more efficient streaming API