XmlDocument 转换为xml字符串

前端之家收集整理的这篇文章主要介绍了XmlDocument 转换为xml字符串前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
static public string XMLDocumentToString(XmlDocument doc)
{
MemoryStream stream = new MemoryStream();
XmlTextWriter writer = new XmlTextWriter(stream,null);
writer.Formatting = Formatting.Indented;
doc.Save(writer);

StreamReader sr = new StreamReader(stream,System.Text.Encoding.UTF8);
stream.Position = 0;
string xmlString = sr.ReadToEnd();
sr.Close();
stream.Close();

return xmlString.Replace("<?xml version=\"1.0\"?>",""); }

原文链接:https://www.f2er.com/xml/297939.html

猜你在找的XML相关文章