I need to read large xml using .net files which can easily be several GB of size.
I tried to use XDocument, but it just throws an System.OutOfMemoryException when I try to load the document.
What is the most performant way to read XML files of large size?
You basically have to use the “pull” model here –
XmlReaderand friends. That will allow you to stream the document rather than loading it all into memory in one go.Note that if you know that you’re at the start of a “small enough” element, you can create an
XElementfrom anXmlReader, deal with that using the glory of LINQ to XML, and then move onto the next element.