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

后端 未结 5 662
死守一世寂寞
死守一世寂寞 2020-12-03 11:13

I have a 1GB XML file and want to parse it. If I use XML Textreader or XMLDocument, the result is very slow and some times it hangs...

5条回答
  •  天涯浪人
    2020-12-03 12:14

    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.
    }
    

提交回复
热议问题