我正在尝试在.NET 2.0中加载xslt转换。我正在内存中加入一个XML Document,因为它是事先动态生成的。当我使用带有ProhibitDTD = false的XMLReader选项时,我收到一条错误消息,说我需要在XsltSettings中启用脚本。如果我使用XsltSettings(可信)的Load方法,我得到DTD错误。关于如何同时应用ProhibitDTD = false和EnableScript = true?
的任何想法 public static string ConvertXML(XmlDocument InputXMLDocument, string XSLTFilePath, XsltArgumentList XSLTArgs)
{
StringWriter sw = new System.IO.StringWriter();
XslCompiledTransform xslTrans = new XslCompiledTransform();
XmlReaderSettings settings = new XmlReaderSettings();
settings.ProhibitDtd = false;
XmlReader reader = XmlReader.Create(XSLTFilePath, settings);
try
{
//xslTrans.Load(reader);
xslTrans.Load(XSLTFilePath, XsltSettings.TrustedXslt, new XmlUrlResolver());
xslTrans.Transform(InputXMLDocument.CreateNavigator(), XSLTArgs, sw);
return sw.ToString();
}
答案 0 :(得分:0)
我明白了 - 有一个重载的方法,对于正确的类型似乎不太明显,但是它有效。
public static string ConvertXML(XmlDocument InputXMLDocument, string XSLTFilePath, XsltArgumentList XSLTArgs)
{
StringWriter sw = new System.IO.StringWriter();
XslCompiledTransform xslTrans = new XslCompiledTransform();
XmlReaderSettings settings = new XmlReaderSettings();
settings.ProhibitDtd = false;
XmlReader reader = XmlReader.Create(XSLTFilePath, settings);
try
{
xslTrans.Load(reader, XsltSettings.TrustedXslt, new XmlUrlResolver());
// xslTrans.Load(XSLTFilePath, XsltSettings.TrustedXslt, new XmlUrlResolver());
xslTrans.Transform(InputXMLDocument.CreateNavigator(), XSLTArgs, sw);
return sw.ToString();
}
catch (Exception ex)
{
//Error email code omitted
}
return "";
}