C#XmlDocument输出字符串

XmlDocument xmlDoc = new XmlDocument();

//假定该xmlDoc已经有内容;

MemoryStream streamXml = new MemoryStream();
XmlTextWriter writer = new XmlTextWriter(streamXml, Encoding.UTF8);
writer.Formatting = Formatting.Indented;
xmlDoc.Save(writer);

StreamReader reader = new StreamReader(streamXml, Encoding.UTF8);
streamXml.Position = 0;
String content = reader.ReadToEnd();
reader.Close();
streamXml.Close();

Console.WriteLine(content);

猜你喜欢

转载自www.cnblogs.com/LCLBook/p/11002707.html