XslLoadException:禁止解析外部 URI [英] XslLoadException: Resolving of external URIs was prohibited

查看:37
本文介绍了XslLoadException:禁止解析外部 URI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 xslt 表,其中包含另一个 xslt 文件的标签,所有文件都编译正确且没有错误,但是当运行以下代码时,我遇到了异常

I have xslt sheet the have include tags for another xslt files, the all files compiled right and error free but when run the following code i got exception

var myXslTrans = new XslCompiledTransform();
XsltSettings sets = new XsltSettings();
sets.EnableScript = true;
myXslTrans.Load("visio.xsl",sets,null);
myXslTrans.Transform("page1.xml", "page.html");

遵循异常文本和堆栈跟踪:

following the exception text and stacktrace:

System.Xml.Xsl.XslLoadException: 
  XSLT compile error. An error occurred \bin\Debug\visio.xsl(116,40). 
  ---> System.Xml.XmlException: Resolving of external URIs was prohibited.
    at System.Xml.Xsl.Xslt.XsltLoader.Load(XmlReader reader)
       at System.Xml.Xsl.Xslt.XsltLoader.Load(Compiler compiler, Object stylesheet, XmlResolver xmlResolver)
       at System.Xml.Xsl.Xslt.Compiler.Compile(Object stylesheet, XmlResolver xmlResolver, QilExpression& qil)
       at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
       at System.Xml.Xsl.XslCompiledTransform.Load(String stylesheetUri, XsltSettings settings, XmlResolver stylesheetResolver)

我尝试通过这个来解决问题,但问题仍然存在

I try to solve the problem by this but the problem still exist

推荐答案

引用评论/更新问题:

我将文件复制到项目中以使用它,路径变量用于获取应用程序的基目录

i copy the files to the project to use it, path variable to get the base directory for the app

是的,但是没有使用路径变量,所以没有效果.

Yes, but the path variable is not used, so it has not effect.

System.Xml.Xsl.XslLoadException:XSLT 编译错误.发生错误 \bin\Debug\visio.xsl(116,40).---> System.Xml.XmlException:禁止解析外部 URI.

System.Xml.Xsl.XslLoadException: XSLT compile error. An error occurred \bin\Debug\visio.xsl(116,40). ---> System.Xml.XmlException: Resolving of external URIs was prohibited.

这可能意味着以下几件事中的一项或多项:

This may mean one or more of several things:

  • 您的设置不允许加载外部文档(这是 XslCompiledTransform 的默认设置,请参阅文档).
  • 您的样式表直接(通过 xsl:importxsl:includedocument())或间接(通过DTD 或解析外部​​实体).
  • 如果上述内容不(完全)正确,至少错误指向问题所在.您没有在问题中复制此内容,但您会在 (116, 40) 中找到它.
  • Your settings do not allow loading external documents (this is the default for XslCompiledTransform, see documentation).
  • Your stylesheet contains a URI either directly (through xsl:import, xsl:include, document()) or indirectly (via a DTD or to resolve external entities).
  • If the above is not (entirely) true, at least the error points to exactly the point where the problem is. You didn't copy this in your question, but you will find it at (116, 40).

要解决,只需允许加载外部文件:

替换这个:

XsltSettings sets = new XsltSettings();
sets.EnableScript = true;

这样:

XsltSettings sets = new XsltSettings(true, true);

更新(在您发表评论后)

我注意到另一件事.您将最后一个参数设置为 null,即 根据微软的说法应该给你一个 ArgumentNullException.它不允许为空,但显然微软现在允许它但是它的效果是 UriResolver 不能解析任何东西,因为嘿,它是空的...

Update (after your comment)

I noticed another thing. You are setting the last argument to null, which according to Microsoft should give you a ArgumentNullException. It is not allowed to be null, but apparently Microsoft now allows it but then it has the effect that the UriResolver cannot resolve anything, because hey, it is null...

不太清楚为什么将其设置为 null,但尝试将其设置为有效值,即:

Not quite sure why you set it to null, but try setting it to a valid value, i.e.:

var resolver = new XmlUrlResolver();
myXslTrans.Load("visio.xsl", sets, resolver);

这篇关于XslLoadException:禁止解析外部 URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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