使用 C# 在内存中进行 XSLT 转换
大家下午好,
我不知道为什么这会如此困难,但我一定会度过这样的日子!
我正在尝试对内存中的 XmlDocument (我已从 Web 服务检索 XML 并保存到数据库)对象执行 XslCompiledTransform 。到目前为止,我有以下代码:
string xslFile = "C:\\MOJLogViewer\\GetClaimTransformed.xslt";
XslCompiledTransform processor = new XslCompiledTransform();
processor.Load(xslFile);
MemoryStream ms = new MemoryStream();
processor.Transform(xdoc.CreateNavigator(), null, ms);
ms.Seek(0, SeekOrigin.Begin);
StreamReader reader = new StreamReader(ms);
XmlDocument transformedDoc = new XmlDocument();
transformedDoc.Load(reader.ReadToEnd());
string output = reader.ReadToEnd();
ms.Close();
当我尝试运行此代码时,出现“路径中的非法字符”异常。该路径不包含任何非法字符,所以我完全被难住了!
我希望你能帮忙。
谢谢
Good afternoon all,
I dont know why this is proving so difficult but I must be having one of those days!
I am trying to perform and XslCompiledTransform on an in memory XmlDocument (I have retrieved the XML from a webservice and saved to a database) object. I have the following code so far:
string xslFile = "C:\\MOJLogViewer\\GetClaimTransformed.xslt";
XslCompiledTransform processor = new XslCompiledTransform();
processor.Load(xslFile);
MemoryStream ms = new MemoryStream();
processor.Transform(xdoc.CreateNavigator(), null, ms);
ms.Seek(0, SeekOrigin.Begin);
StreamReader reader = new StreamReader(ms);
XmlDocument transformedDoc = new XmlDocument();
transformedDoc.Load(reader.ReadToEnd());
string output = reader.ReadToEnd();
ms.Close();
When I try to run this code I get the "illegal characters in path" exception. The path does not contain any of the illegal characters so I am absolutely stumped!
I hope you can help.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Load
从路径读取;您可能需要transformedDoc.LoadXml(...)
。但老实说,您可以将整个内容写入StringWriter
- 更直接:而且它适用于非 xml 输出(xslt 没有义务输出 xml)。
Load
reads from a path; you probably wanttransformedDoc.LoadXml(...)
. But in all honesty, you could just write the whole thing to aStringWriter
- more direct:Plus it will work for non-xml outputs (xslt is not obliged to output xml).