zoukankan      html  css  js  c++  java
  • 无缩进的XML字符串的处理

    加上缩进,输出xml字符串,代码:

    using System.Xml;
    using System.Text;
     
    /// <summary>
    /// Format xml string without indent 
    /// to xml string with indent 
    /// </summary>
    /// <param name="source">xml string without indent </param>
    /// <returns>xml string with indent </returns>
    private string FormatXml(string source)
    {
        StringBuilder sb = new StringBuilder();
        XmlTextWriter writer = null;
     
        try
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(source);
     
            writer = new XmlTextWriter(new StringWriter(sb));
            writer.Formatting = Formatting.Indented;
     
            doc.WriteTo(writer);
        }
        finally
        {
            if (writer != null) writer.Close();
        }
     
        return sb.ToString();
    }
  • 相关阅读:
    Python Day14
    Python Day13
    Python Day12
    Python Day11
    Python Day10
    Python Day9
    Python Day8
    Python Day7
    Python Day6
    Python Day5
  • 原文地址:https://www.cnblogs.com/Mainz/p/1179453.html
Copyright © 2011-2022 走看看