C#文本之XML

2021-06-08 05:03

阅读:338

标签:bsp   iter   stream   str   contain   orm   for   end   报文   

 

 

格式化XML

 public static string FormatXML(string XMLstring)
        {
           //校验是否是XML报文
            if (!XMLstring.Contains("")) return XMLstring;           
            XmlDocument document = new XmlDocument();
            document.LoadXml(XMLstring);          

            MemoryStream memoryStream = new MemoryStream();
            XmlTextWriter writer = new XmlTextWriter(memoryStream, null)
            {
                Formatting = Formatting.Indented//缩进
            };
            document.Save(writer);
            StreamReader streamReader = new StreamReader(memoryStream);
            memoryStream.Position = 0;
            string xmlString = streamReader.ReadToEnd();
            streamReader.Close();
            memoryStream.Close();
            return xmlString;
        }

 

C#文本之XML

标签:bsp   iter   stream   str   contain   orm   for   end   报文   

原文地址:https://www.cnblogs.com/code1992/p/10704928.html


评论


亲,登录后才可以留言!