Ahmed Moheb
Ahmed Moheb

Reputation: 762

XMLDocument VS XmlReader which is more efficient to validate well-formed XML in C#

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.

Upvotes: 0

Views: 397

Answers (2)

Gregory A Beamer
Gregory A Beamer

Reputation: 17010

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.

Upvotes: 0

Ahmed Moheb
Ahmed Moheb

Reputation: 762

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

Upvotes: 1

Related Questions