C#:使用XSLTClass将XML转换为doc时出现问题

编程入门 行业动态 更新时间:2024-10-10 01:27:54
本文介绍了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 "&#160;"> ]> <xsl:stylesheet version="1.0" xmlns:xsl="www.w3/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&nbsp;Test</h1> </body> </html> </xsl:template> </xsl:stylesheet>

更多推荐

C#:使用XSLTClass将XML转换为doc时出现问题

本文发布于:2023-10-31 10:36:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545828.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   XSLTClass   XML   doc

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!