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);