在c#中加载xml时出现OutOfMemory异常

本文关键字:OutOfMemory 异常 xml 加载 | 更新日期: 2023-09-27 18:18:24

当在树视图中执行下面的代码时,我得到outofmemory异常。

XmlTextReader reader = new XmlTextReader(vConditionPaths.InputLogXmlPath);
_inputItenLogDoc.Load(reader);
reader.Close();

其中vConditionPaths.InputLogXmlPath为xml的路径,_inputItenLogDoc为在类中声明为局部变量的XmlDocument

请帮

在c#中加载xml时出现OutOfMemory异常

我假设您的xml文件太大,无法由XmlTextReader处理。(因为XmlTextReader会尝试一次读取整个xml文件)

您可以尝试执行顺序解析的SAX解析器。见http://en.wikipedia.org/wiki/Simple_API_for_XML

参见http://saxdotnet.sourceforge.net/

为c#解决方案。据我所知,没有原生的。net框架sax解析器解决方案。也许还有人知道。net的新sax解析器?我很感兴趣:-)