C# 中的 XslCompiledTransform 调试

发布于 2024-07-11 05:44:21 字数 1218 浏览 7 评论 0原文

我已经尝试了很多次,但我无法在不从磁盘加载样式表(通过将 URI 传递到 XslCompiledTransform.Load() 方法)的情况下进入 XslCompiledTransform。

我完全清楚,如果您通过 URI(如上所述)从磁盘加载样式表,或者从实现 IXmlLineInfo 接口的 XmlReader 加载样式表,则只能进入 XslCompiledTransform.Transform() 方法。

我已加载样式表如下:

XslCompiledTransform xslt = new XslCompiledTransform(true);
//grab string from textbox
XmlReader reader = XmlReader.Create(new StringReader(XsltBox.Text));

// Compile the style sheet.
xslt.Load(reader);

从我读过的各种文献来看,这似乎是启用调试的方式。 但是,当我尝试进入 XslCompiledTransform.Transform() 方法时,我收到消息:“当前位置没有可用的源代码”

如前所述,如果我执行以下操作,我可以进入转换以下:

string stylesheet = @"C:\PathToMy\Stylesheet.xsl";

// Enable XSLT debugging.
XslCompiledTransform xslt = new XslCompiledTransform(true);
//compile stylesheet
xslt.Load(stylesheet);

上述方法是不可能的,因为我不希望不断地从磁盘读取数据。


感谢您的有用评论,我没有意识到微软已经做到了这一点,我相信这将在未来非常有帮助。

但是,我想我的问题并没有完全清楚地表达出来。 我没有考虑进入加载方法,我想进入转换方法,这样我就可以看到 xsl 转换发生了什么。 我强调了 load 方法,因为您传入的参数决定了您是否能够调试转换方法(您必须传入实现 IXmlLineInfo 接口的 XmlReader 才能执行此操作)。

虽然我可以使用您强调的技术进入转换方法,但我只是单步执行代码。 尽管我可以通过观察代码来了解转换发生的情况,但 xsl 调试器会逐行显示实际样式表本身的单步执行(而不是执行转换的每一行的代码)

i've tried and tried and tried but i cannot manage to step into the XslCompiledTransform without having to load the stylesheet from disk (by passing a URI into the XslCompiledTransform.Load() method).

I am fully aware that you can only step into the XslCompiledTransform.Transform() method if you loaded the stylesheet from disk via URI (as mentioned) or by loading the stylesheet from an XmlReader that implements the IXmlLineInfo interface.

I have loaded the stylesheet as follows:

XslCompiledTransform xslt = new XslCompiledTransform(true);
//grab string from textbox
XmlReader reader = XmlReader.Create(new StringReader(XsltBox.Text));

// Compile the style sheet.
xslt.Load(reader);

This seems to be, from the various literature i have read, the way in which debugging can be enabled. However when i try to step into the XslCompiledTransform.Transform() method i get the message: "There is no source code available for the current location"

As mentioned I can step into the transformation if I do the following:

string stylesheet = @"C:\PathToMy\Stylesheet.xsl";

// Enable XSLT debugging.
XslCompiledTransform xslt = new XslCompiledTransform(true);
//compile stylesheet
xslt.Load(stylesheet);

The above method is not possible as I do not wish to be reading to and from disk constantly.


thanks you for that useful comment, i did not realise microsoft had done this, i'm sure this will prove very helpful in future.

however, i guess i didn't make myself entirely clear in my question. i was not looking into stepping into the load method, i wanted to step into the transform method so i could see what was happening with the xsl transformation. i emphasised the load method because the parameter you pass in dictates whether you are able to debug the transform method (you must pass in an XmlReader which implements the IXmlLineInfo interface to do so).

whilst i could step into the transform method using the technique you highlighted, i would merely be stepping through the code. though i could potentially work out what was hapening with the transformation through observing the code, the xsl debugger shows the stepping through of the actual stylesheet itself line by line (as opposed to the code which executes each line of the transformation)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉殇 2024-07-18 05:44:21

最近,Microsoft 发布了 .Net Framework 的符号和源代码,以允许在此类情况下进行调试。 设置需要几秒钟,但一旦完成,无论您如何构建 XslCompiledTransform,您都应该能够进入 Load 方法。

它太详细了,无法给出如此答案,但这里有一篇关于该主题的优秀博客文章。

http: //codebetter.com/blogs/james.kovacs/archive/2008/01/17/debugging-into-the-net-framework-source.aspx

Recently Microsoft released the symbols and source code for the .Net Framework to allow for debugging in such scenarios. It takes a few seconds to setup but once you've done it you should be able to step into the Load method regardless of how you built the XslCompiledTransform.

It's too detailed to go into an SO answer but here is an excellent blog post on the subject.

http://codebetter.com/blogs/james.kovacs/archive/2008/01/17/debugging-into-the-net-framework-source.aspx

绝對不後悔。 2024-07-18 05:44:21

我在尝试使用 XmlReader.Create(new StringReader(String)) 时遇到了同样的问题。
看来调试器必须能够找到磁盘文件才能进行调试,但这并不意味着不能使用 StringReader 或流版本的 XmlReader.Create 。 尝试这个版本:

XmlReader.Create(new StringReader(String), New XmlReaderSettings(), baseURI)

在我的例子中,我使用文件资源来存储我的 xslt 字符串,因此有一个我可以指向的文件。 事实上,您不需要提供调试器知道的绝对路径来在解决方案/属性/调试器源代码下指定的文件夹中搜索源代码。

XslCompiledTransform 的文档具有误导性,因为它暗示所需要的只是一个支持 IXmlLineInfo 接口的 XmlReader

I have been having the same problem while trying to use XmlReader.Create(new StringReader(String)).
It seems the debugger must be able to find a disk file for the debugging to work but this does not mean that StringReader or stream version of XmlReader.Create cannot be used. Try this version:

XmlReader.Create(new StringReader(String), New XmlReaderSettings(), baseURI)

In my case I am using a file resource to store my xslt string so there is a file I can point to. In fact you do not need to give an absolute path the debugger will know to search for source code in folders that are specified under Solution/Properties/Debugger Source code.

The documentation for XslCompiledTransform is misleading because it implies that all that is requires is an XmlReader supporting the IXmlLineInfo interface.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文