阅读471 返回首页    go 阿里云 go 技术社区[云栖]


C# 将XmlDocument转化为string函数

 	/// <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;
        }

最后更新:2017-04-03 12:54:19

  上一篇:go System.Configuration.ConfigurationSettings.GetConfig(string)”已过时
  下一篇:go 遍历获取Xml子节点值