XslCompiledTransform 输出为 XPathDocument
我正在尝试使用 XslCompiledTransform,并将输出用作 XPathDocument。
有什么想法吗?
I am trying to use a XslCompiledTransform, and use the output as a XPathDocument.
Any Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
琼斯先生的回答对我很有帮助,但我发现最后一行不起作用。我最终这样做了:(
这里,xPathDoc 是一个已经从 XmlReader 初始化的 XPathDocument。)
Mr. Jones's answer was very helpful for me, but I found that the last line didn't work. I ended up doing this:
(Here, xPathDoc is an XPathDocument that has already been initialized from an XmlReader.)
将转换发送到基于
StringWriter
的XmlTextWriter
。然后通过从StringWriter
检索 XML 字符串来实例化XPathDocument
。它不是最高效的内存机制,但足以满足大多数需求。类似的方法是使用
MemoryStream
而不是StringWriter
,但相比之下它有点混乱。Send the transform to an
XmlTextWriter
based on aStringWriter
. Then instance theXPathDocument
by retreiving the XML string from theStringWriter
.Its not the most memory efficient mechanism but will be adequate for most needs. A similar approach would be use a
MemoryStream
instead of aStringWriter
but its a little messy by comparison.David M. Anderson 的答案稍微好一点的形式如下:它不会遭受潜在的资源泄漏;否则都是一样的。
A slightly better form of David M. Anderson's answer is below: it does not suffer from potential resource leaks; otherwise it is the same.