XML读者想ProhibitDTD是假的,但它是! [英] XML Reader wants ProhibitDTD to be false but it is!

查看:553
本文介绍了XML读者想ProhibitDTD是假的,但它是!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是code     流流= request.InputStream;

Here is the code Stream stream = request.InputStream;

String xsd = // Path to file

XmlReaderSettings settings = new XmlReaderSettings();
if (xsd.Length != 0 && File.Exists(xsd))
{
	settings.ProhibitDtd = false;
	settings.Schemas.Add("", xsd);
	settings.ValidationType = ValidationType.Schema;

}
else
{
	throw new cXMLException("XSD file not found", ResponseStatus.InternalServerError);
}

using (XmlReader reader = XmlReader.Create(stream, settings))
{
	XmlDocument doc = new XmlDocument();

	// Attempt to validate the XML document
	try
	{
		doc.Load(reader);
	}
	catch (XmlSchemaValidationException e)
	{
		StringBuilder sb = new StringBuilder("Invalid cXML document. Reason: ");
		sb.Append(e.Message);
		String message = sb.ToString();
		throw new cXMLException(message, ResponseStatus.BadRequest);
	}

	return new cXMLBasicResponse("Everything OK", ResponseStatus.OK);
}

出于某种原因,不断要求将ProhibitDtd是假的。但正如你所看到的我已经有!下面是例外

For some reason it keeps asking me to set "ProhibitDtd" to be false. But as you can see I already have! Below is the exception

System.Xml.XmlException: 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.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.ThrowWithoutLineInfo(String res, String arg)
   at System.Xml.XmlTextReaderImpl.ParseDoctypeDecl()
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.Schema.Parser.StartParsing(XmlReader reader, String targetNamespace)
   at System.Xml.Schema.Parser.Parse(XmlReader reader, String targetNamespace)
   at System.Xml.Schema.XmlSchemaSet.ParseSchema(String targetNamespace, XmlReader reader)
   at System.Xml.Schema.XmlSchemaSet.Add(String targetNamespace, String schemaUri)
   at cXML.ResponseFactory.requestReader(HttpRequest request)

任何想法,将大大AP preciated。

Any thoughts would be greatly appreciated.

推荐答案

我犯了一个错误,我传递一个DTD(而不是XSD),并混淆了整个事情。

I made a mistake, I was passing it a DTD (not an XSD) and confusing the whole thing.

这篇关于XML读者想ProhibitDTD是假的,但它是!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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