Using LINQ to XML will read the entire file in memory.
If you are reading a huge XML file (hundreds of megabytes), this is a problem.
Instead, you can use a raw XmlReader, which provides only an XML file view only forward and will not read the entire file at once.
If you are dealing with normal sized XML files, LINQ to XML will be fine.
LINQ to XML is several orders of magnitude easier to use than XmlReader.
You should only use XmlReader if you know that you are dealing with 200MB XML files or if you measured your performance and proved that the XDocument constructor is too slow.
SLaks
source share