gpt4 book ai didi

xml - 如何指定 "Custom Tool"以在 VS2010 中转换文件?

转载 作者:数据小太阳 更新时间:2023-10-29 01:48:13 25 4
gpt4 key购买 nike

VS2010 中大多数文件类型(例如 .cs、.xml、.xslt)的“属性”窗口允许指定用于转换文件的自定义工具。作为引用,这里是选择“自定义工具”字段时获得的工具提示。

Specifies the tool that transforms a file at design time and places the output of that transformation into another file. For example, a dataset (.xsd) file comes with a default custom tool.

我正在查找有关如何设置和使用此属性的信息。

这是我要解决的问题。我正在通过应用 XSLT 转换 XML 文件。我在转换期间使用扩展对象,如所述 here .

在这样做的过程中,我使 Visual Studio 无法用作编辑和调试 XSLT 的工具。我希望我可以编写一个简单的转换引擎,使我们能够像处理不使用扩展对象的 XSLT 文档一样使用 Visual Studio。我认为(希望)自定义工具属性是完成这项工作的关键。

TIA

最佳答案

使用扩展函数调试 XSLT 转换,能够在 XSLT 代码和扩展函数代码中设置断点,因为 VS2005 已经支持

只需使用 this XslCompiledTransform constructor过载

参数启用调试类型:System.Booleantrue 生成调试信息;否则为假。将此设置为 true 使您能够使用 Microsoft Visual Studio 调试器调试样式表。

备注

必须满足以下条件才能单步执行代码并调试样式表:

enableDebug 参数设置为 true。

  • 样式表被传递给Load方法作为 URI,或XmlReader 类的实现实现了 IXmlLineInfo界面。 IXmlLineInfo 接口(interface)在所有文本解析上实现XmlReader 对象。

    换句话说,如果样式表是使用 IXPathNavigable 加载对象,例如 XmlDocumentXPathDocument,或 XmlReader不执行实现 IXmlLineInfo 接口(interface),您无法调试样式表。

  • XmlResolver 用于加载样式表是基于文件的XmlResolver,例如XmlUrlResolver(这是默认的XmlResolver 使用的XslCompiledTransform 类)。

  • 样式表位于本地机器或 Intranet 上。

这是一个小代码示例:

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

// Load the style sheet.
xslt.Load("output.xsl");

// Create the writer.
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent=true;
XmlWriter writer = XmlWriter.Create("output.xml", settings);

// Execute the transformation.
xslt.Transform("books.xml", writer);
writer.Close();

关于xml - 如何指定 "Custom Tool"以在 VS2010 中转换文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4737997/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com