C# 在C中根据DTD验证XML时出现问题#
这已经困扰我好几天了。我试图将上传文件中的XML加载到XmlDocument对象中,并获得以下死亡黄屏:C# 在C中根据DTD验证XML时出现问题#,c#,asp.net,xml,dtd,C#,Asp.net,Xml,Dtd,这已经困扰我好几天了。我试图将上传文件中的XML加载到XmlDocument对象中,并获得以下死亡黄屏: 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 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.
这是我的密码。你可以清楚地看到我将prohibidtd设置为false
public static XmlDocument LoadXml(FileUpload fu)
{
var settings = new XmlReaderSettings
{
ProhibitDtd = false,
ValidationType = ValidationType.DTD
};
var sDtdPath = string.Format(@"{0}", HttpContext.Current.Server.MapPath("/includes/dtds/2.3/archivearticle.dtd"));
settings.Schemas.Add(null, sDtdPath);
var r = XmlReader.Create(new StreamReader(fu.PostedFile.InputStream), settings);
var document = new XmlDocument();
document.Load(r);
return document;
}
将
XmlResolver=null
添加到XmlReaderSettings
中。这将阻止xmlDocument尝试访问DTD。如果需要验证,请在单独的操作中进行验证