如何让DTD在通过XSLT的文档(URI)函数与XslCompiledTransform加载XML文档(.NET) [英] How to allow DTD in XML Documents loaded via XSLT's document(uri) function with XslCompiledTransform (.NET)

查看:130
本文介绍了如何让DTD在通过XSLT的文档(URI)函数与XslCompiledTransform加载XML文档(.NET)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档(URI)函数用于在XSLT,其中目标文档包含DTD我得到一个 XslTransformException中加载另一个文件,包含一个内 XmlException

When the document(uri) function is used to load another document within the XSLT, where the target document contains a DTD I get an XslTransformException, containing an inner XmlException:

有关安全方面的原因DTD禁止在此XML文档研究。要启用DTD处理上XmlReaderSettings设置为false的ProhibitDtd属性,并通过设置成XmlReader.Create方法。

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.

由于的XmlReader 的XSLT实现没有直接的方法来创建与我想要的设置的XmlReader,并没有内创建 XslCompiledTransform 的XmlResolver 1 或相关类似乎提供任何形式的钩子。

As the XmlReader is created within the XSLT implementation there is no direct way to create the XmlReader with the settings I want, and none of the XslCompiledTransform, XmlResolver1 or related classes seem to provide any form of hook.

(我使用DTD来设置一些HTML实体,以使文档更容易的创作。)

(I'm using a DTD to set some HTML entities to make the authoring of the document easier.)

1 基于看着 XmlUrlResolver 在反射这个刚刚加载的URI的目标作为一个流。

1 based on looking at XmlUrlResolver in Reflector this just loaded the URI's target as a Stream.

例如。是XSLT包含

<xsl:apply-templates select="document('more.xml')/root"/>

more.xml 包含一个DTD,然后上面的例外是结果。

and more.xml contains a DTD then the exception above is the result.

推荐答案

同样的XmlResolver 传递给变换方法用于文件的功能,这个解析器可以返回一个的XmlReader ,允许,而不是返回DTD,。您也可以返回 IXPathNavigable 。换句话说,你需要一个专门的实施的XmlResolver 来解决这个问题。

The same XmlResolver you pass to the Transform method is used for document function, this resolver can return an XmlReader that allows DTD, instead of returning Stream. You can also return IXPathNavigable. In other words, you need a specialized implementation of XmlResolver to fix this issue.

这篇关于如何让DTD在通过XSLT的文档(URI)函数与XslCompiledTransform加载XML文档(.NET)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆