2009-11-23 29 views
1

以下是代碼 Stream stream = request.InputStream;XML Reader希望ProhibitDTD是假的,但它是!

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」是假的。但正如你所看到的,我已經擁有了!下面是例外

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) 

任何想法將不勝感激。

+0

感謝@AakashM的編輯清理它。 – tgandrews 2009-11-23 13:52:16

回答

0

我犯了一個錯誤,我傳遞給它一個DTD(不是XSD)並且混淆了整個事情。

相關問題