开发者

How I can read an xml file with limited memory?

            var q = from n in XElement.Load(Application.StartupPath + "..\\..\\..\\2.xml").Elements()
                    select n;
            foreach (var q0 in q)
            {
                string str = q0.ToString();
            }

the problem is my xml file is so big so how I can manage this code to load it gradually not completely. now I traced by c# it loads all file completely in "q" and then loads some big nodes in "str". I have limited memory and I 开发者_运维知识库need loading from file a little by little. I dont know how many nodes I have but I know general structure of file.


Instead of reading the whole XML file in memory at once and then iterating over it, check out the XmlReader class and its derivatives. These allow you to traverse your XML node per node.

XmlTextReader is a particular derivative for reading XML from text files.

Check out http://support.microsoft.com/kb/307548.


You would use an XmlReader. The problem with using this is that the processing is completely different, you can't use LINQ.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜