What is the best way to parse large XML (size of 1GB) in C#? What is the best way to parse large XML (size of 1GB) in C#? xml xml

What is the best way to parse large XML (size of 1GB) in C#?


You'll have to implement custom logic using xmlreader. xmlreader does not load the full XML into memory before using it, which means you can read it from a stream and process it as such.


XmlDocument is not feasible in this scenario as it will attempt to suck that gigabyte into main memory. I'm surprised that you're finding XmlTextReader to be too slow. Have you tried something like the following?

using (XmlTextReader rdr = new XmlTextReader("MyBigFile.txt")){     // use rdr to advance through the document.}


XMLTextreader isn't supposed to hang as it's stream based and just works on chunks of the data.

If it hangs, it may well be that you are doing something wrong when loading the file.