【发布时间】:2016-04-29 12:19:31
【问题描述】:
我正在尝试使用 XMLWriter 将字符串(只不过是 XMLNodes)写入新的 XML 文件
XmlWriter writer = XmlWriter.Create(@"C:\\Test.XML")
writer.WriteStartDocument();
writer.WriteStartElement("Test");
string scontent = "<A a="Hello"></A><B b="Hello"></B>";
XmlReader content = XmlReader.Create(new StringReader(scontent));
writer.WriteNode(content, true);
//Here only my first node comes in the new XML but I want complete scontent
writer.WriteEndElement();
预期输出:
<Test>
<A a="Hello"></A>
<B b="Hello"></B>
</Test>
【问题讨论】:
-
如果你想写
string,为什么要使用XmlWriter?File.WriteAllText应该可以正常工作。 -
@MikeStrobel 我无法使用 File.WriteAllText,因为我正在节点之间编写 XML 元素。谢谢。
标签: c# xml string xmlreader xmlwriter