System.Xml.dll中发生了未处理的“System.OutOfMemoryException”类型异常

时间:2011-03-22 05:45:37

标签: c# .net xml out-of-memory xmldocument

我有以下代码:

XmlTextReader DBLPReader = new XmlTextReader("dblp.xml");

// Load the source of the XML file into an XmlDocument
XmlDocument DBLPDoc = new XmlDocument();

// Load the source XML file into the first document
DBLPDoc.Load(DBLPReader);

// Close the reader
DBLPReader.Close();`

其中dblp大约有800 MB。

我收到一条错误消息“System.Xml.dll中发生了'System.OutOfMemoryException'类型的未处理异常”

这种情况下的解决方案是什么?

2 个答案:

答案 0 :(得分:0)

根据您要完成的任务,您的解决方案可能是:

  • 使用SAX解析器。
  • 使用64位计算机。
  • 不要尝试加载这么大的文件。
  • 缩小文件(例如,删除空格或注释,缩短标签名称)。
  • 抓住异常并妥善处理。

答案 1 :(得分:0)

如果你要搞乱那个大小的XML文件,你应该考虑使用System.Xml.XmlTextReader。它列出了它将为您提供here的内容,以及关于如何使用here的体面教程。

相关问题