c# - 在 C# 中从 XML Writer 创建 XML 元素对象

标签 c# xml xmlwriter

我正在用 C# 编写一个 Windows 服务。我有一个 XmlWriter,它包含 XSLT 转换的输出。我需要将 XML 放入 XMLElement 对象中以传递给 Web 服务。

执行此操作的最佳方法是什么?

最佳答案

您不需要中间字符串,您可以创建一个直接写入 XmlNode 的 XmlWriter:

XmlDocument doc = new XmlDocument();
using (XmlWriter xw = doc.CreateNavigator().AppendChild()) {
  // Write to `xw` here.
  // Nodes written to `xw` will not appear in the document 
  // until `xw` is closed/disposed.
}

并将 xw 作为转换的输出传递。

注意。 xsl:output 的某些部分将被忽略(例如编码),因为 XmlDocument 将使用其自己的设置。

关于c# - 在 C# 中从 XML Writer 创建 XML 元素对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/560842/

相关文章:

C#/Mono - 从控制台应用程序读取输出

c# - xmlwriter 在一行中写入元素

iphone - XML文件怎么写?

c# - 我需要在一个元素中使用 XmWriter 的多个 xmlns 元素

c# - 记录即发即弃任务中的异常

c# - 将 Gmap.net 标记与计时器一起使用

android - 想 toast 的用户名,但是当我尝试登录时却给了我很大的压力

java - JAXB 无法处理包含空格的 XML 元素到 java.net.URI 的映射

java - 可扩展列表 : different background colors for ListGroup Items

c# - 如何准确刷新ProgressBar