XmlException:输入文档已超过MaxCharactersFromEntities设置的限制

编程入门 行业动态 更新时间:2024-10-15 08:23:45
本文介绍了XmlException:输入文档已超过MaxCharactersFromEntities设置的限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个XML文件,如下所示:

I have an XML file that looks like this:

<!DOCTYPE Root [ <!ELEMENT anEntity (#PCDATA)> <!ELEMENT 500SuchElementsHere (#PCData)> <!ENTITY file1 SYSTEM "file1.xml"> ... <!ENTITY file25 SYSTEM "file25.xml"> ]> <Root> &file1; &file2; ... &file25; </Root>

我正在使用XmlDocument这样加载XML文件

I'm loading the XML file using XmlDocument like this

XmlDocument doc = new XmlDocument(); doc.Load("filePath to the above xml file");

加载会抛出标题中提到的异常。我在Windows 7 Ultimate上运行.NET 4.5,VS 2012 Desktop Express。任何帮助是赞赏。谢谢

The load throws the exception mentioned in the title. I'm running .NET 4.5, VS 2012 Desktop Express on Windows 7 Ultimate. Any help is appreciated. Thanks

推荐答案

您需要使用 XmlReader ,其中包含设置属性 MaxCharactersFromEntities 设置为0(或大量将适用于您的场景):

You need to use an XmlReader with the settings property MaxCharactersFromEntities set to 0 (or a large number that will work for your scenario):

var doc = new XmlDocument(); using (var stream = new MemoryStream(Encoding.Default.GetBytes(xml))) { var settings = new XmlReaderSettings(); // The default is 0, but setting it here allows us to document exactly why we are taking this approach. settings.MaxCharactersFromEntities = 0; using (var reader = XmlReader.Create(stream, settings)) { doc.Load(reader); } }

更多推荐

XmlException:输入文档已超过MaxCharactersFromEntities设置的限制

本文发布于:2023-11-10 16:25:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1575884.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文档   XmlException   MaxCharactersFromEntities

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!