gpt4 book ai didi

.net - 从 XmlDocument 到 XmlDocument 的 XslCompiledTransform

转载 作者:行者123 更新时间:2023-12-02 05:00:42 25 4
gpt4 key购买 nike

我使用以下 VB.NET 代码将一些 XML 转换为新的 XML,然后继续处理。这是一次性过程,而不是多次完成的过程,因此据我所知,缓存不会提高效率。

代码有效,但我发现性能问题。我知道性能问题可能与 XSLT 有关。

我还发现开发人员遇到 XslCompiledTransform 性能问题的实例,尤其是在 64 位环境中,这可能是一个错误 (http://connect.microsoft.com/VisualStudio/feedback/details/508748)

XSLT 性能问题和 XslCompiledTransform 问题都在我的控制之下,但我的代码存在问题是可行的。我只是想确保我执行转换的方法是满足我需要的最有效方法。

Public Function TransformUsingXPathNavigator(ByVal InputXML As XmlDocument, ByVal XSLTLocation As String) As XmlDocument

Dim theNavigator As XPathNavigator
theNavigator = InputXML.CreateNavigator()

Dim theTransform As XslCompiledTransform = New XslCompiledTransform()
theTransform.Load(XSLTLocation)

Dim outputXML As New XmlDocument()

Using writer As XmlWriter = outputXML.CreateNavigator().AppendChild()
theTransform.Transform(theNavigator, writer)
End Using

Return outputXML

End Function

有人能指出我的代码有什么问题吗?

编辑:这是一次性转换,因此没有循环。

最佳答案

我们从未能够使用 XslCompiledTransform 提高代码的效率。

我们能够识别 XSLT 中多次运行的循环,删除代码后,耗时从 60 多秒减少到不到 1 秒。

但是,XSLT 超出了我的控制范围,因此我需要找到替代解决方案。这并不理想,但我不得不回到过时的 XslTransform。

使用 XslTransform,代码运行时间不到 1 秒,这正是我所需要的。

今后我们使用的 XSLT 需要进行整理,但目前使用过时的代码是我的问题的解决方案。

关于.net - 从 XmlDocument 到 XmlDocument 的 XslCompiledTransform,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16568709/

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