在ASP.NET Web [Forms]应用程序(.NET 4.5.2)中,我有以下HTTP Handler(ProcessRequest
方法),它可以正常工作:
XmlReader document = XmlReader.Create(xmlPath, new XmlReaderSettings { DtdProcessing = DtdProcessing.Parse });
StringWriter writer = new StringWriter();
XslCompiledTransform transform = new XslCompiledTransform();
transform.Load(xsltPath);
transform.Transform(document, null, writer);
context.Response.ContentType = "text/html";
context.Response.Write(writer.ToString());
我需要在ASP.NET WebSite项目(.NET 2.0)中的HTTP处理程序中使用上面的代码。我知道代码需要修改如下(因为.NET版本之间存在差异):
XmlReaderSettings xmlSettings = new XmlReaderSettings();
xmlSettings.ProhibitDtd = false;
XmlReader document = XmlReader.Create(xmlPath, xmlSettings);
StringWriter writer = new StringWriter();
XslCompiledTransform transform = new XslCompiledTransform();
transform.Load(xsltPath);
transform.Transform(document, null, writer);
context.Response.ContentType = "text/html";
context.Response.Write(writer.ToString());
我希望代码在两种情况下都能正常工作,但是没有。在第二种情况下,使用完全相同的XML和XSLT文件进行测试时,我总是会收到以下错误:
Expected DTD markup was not found. Line 1, position 1.
排队:
transform.Transform(document, null, writer);
我无法解释为什么。如上所述,XML和XSLT文件在两种情况下完全相同,并且HTTP处理程序在web.config
中正确注册。
更新:以下是XML输入的开始方式:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE article SYSTEM "http://dtd.nlm.nih.gov/publishing/2.3/" [
<!ENTITY bull "•">
<!ENTITY copy "©">
]>
有什么想法吗?