/// <summary>
/// 将XmlDocument转化为string
/// </summary>
/// <param name="xmlDoc"></param>
/// <returns></returns>
public string ConvertXmlToString(XmlDocument xmlDoc)
{
MemoryStream stream = new MemoryStream();
XmlTextWriter writer = new XmlTextWriter(stream, null);
writer.Formatting = Formatting.Indented;
xmlDoc.Save(writer);
StreamReader sr = new StreamReader(stream, System.Text.Encoding.UTF8);
stream.Position = 0;
string xmlString = sr.ReadToEnd();
sr.Close();
stream.Close();
return xmlString;
}
C# 将XmlDocument转化为string函数
XML文档转字符串方法
最新推荐文章于 2024-02-20 10:59:16 发布
本文介绍了一种将XmlDocument对象转换为字符串的方法。通过使用MemoryStream和XmlTextWriter,该方法可以将XML文档保存到内存流中,并以缩进格式进行美化。随后从内存流中读取内容并将其转换为UTF8编码的字符串。
1118

被折叠的 条评论
为什么被折叠?



