DTD禁止xml文件例外 [英] DTD prohibited in xml document exception

查看:1273
本文介绍了DTD禁止xml文件例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到试图通过XML文档中的C#应用​​程序来解析的时候这个错误:

I'm getting this error when trying to parse through an XML document in a C# application:

出于安全原因的DTD

"For security reasons DTD is prohibited in this XML document. To enable DTD processing set the ProhibitDtd property on XmlReaderSettings to false and pass the settings into XmlReader.Create method."

有关参考,异常发生在下面的代码的第二行:

For reference, the exception occurred at the second line of the following code:

using (XmlReader reader = XmlReader.Create(uri))
{
    reader.MoveToContent(); //here

    while (reader.Read()) //(code to parse xml doc follows).



我的XML的知识是非常有限的,我不知道DTD处理也不怎么做错误信息提示。任何帮助,以什么可能会造成这个问题以及如何解决它?谢谢...

My knowledge of Xml is pretty limited and I have no idea what DTD processing is nor how to do what the error message suggests. Any help as to what may be causing this and how to fix it? thanks...

推荐答案

至于解决这个,带着几分环视我发现这是因为添加简单:

As far as fixing this, with a bit of looking around I found it was as simple as adding:

XmlReaderSettings settings = new XmlReaderSettings();
settings.ProhibitDtd = false;

和传递这些设置到创建方法。

and passing these settings into the create method.

这篇关于DTD禁止xml文件例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆