XML Reader 希望 ProhibitDTD 为 false,但事实确实如此!

发布于 2024-08-12 12:01:47 字数 1998 浏览 3 评论 0原文

这是代码 流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”设置为 false。但正如你所看到的,我已经拥有了!以下是例外情况

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)

任何想法将不胜感激。

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);
}

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)

Any thoughts would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凝望流年 2024-08-19 12:01:47

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文