C#:使用XSLTClass将XML转换为doc时出现问题 [英] C# : Problem when transforming XML to doc using XSLTClass
本文介绍了C#:使用XSLTClass将XML转换为doc时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我在使用XSLClass将XML转换为文档时遇到了一个问题。
I am facing an issue when transforming an XML to document using XSLClass.
错误:出于安全原因,此XML文档中禁止使用DTD。要启用DTD处理,请将XmlReaderSettings上的ProhibitDtd属性设置为false,并将设置传递给XmlReader.Create方法
XslCompiledTransform xslt = new XslCompiledTransform();
// Execute the transform and output the results to a file.
xslt.Transform(xmlPath, outputPath);
MessageBox.Show("Success");
有谁知道修复此问题的解决方案?我也尝试过使用XMLreader,请参阅下面的
代码。但是,当编译器在xslt.Transform语句中解析时仍然是同样的错误
Does anyone know the solution to fix this? I have also tried using XMLreader, see below
code. But, still it is the same error when the compiler parses at xslt.Transform statement
XmlReaderSettings xrs = new XmlReaderSettings();
xrs.ProhibitDtd = false;
xrs.XmlResolver = null;
xrs.IgnoreProcessingInstructions = true;
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(XmlReader.Create(xslPath,xrs));
// Execute the transform and output the results to a file.
xslt.Transform(xmlPath, outputPath);
MessageBox.Show("Success");
推荐答案
我无法重现这个问题,例如我的XSLT有一个DOCTYPE节点,如
I can't reproduce the problem, for instance when my XSLT has a DOCTYPE node as in
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp " ">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<html lang="en">
<head>
<title>Test</title>
</head>
<body>
<h1>This is a Test</h1>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
这篇关于C#:使用XSLTClass将XML转换为doc时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文