Format Xml : Xml Format « XML « C# / C Sharp






Format Xml

  

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.IO;

namespace Billing
{
    public class StringUtils
    {
        public static string FormatXml(string xml)
        {
            if (xml == null)
                return "";

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);

            StringWriter strWriter = new StringWriter();
            strWriter.NewLine = "\r\n";

            XmlTextWriter writer = new XmlTextWriter(strWriter);
            writer.Formatting = Formatting.Indented;
            writer.Indentation = 1;
            writer.IndentChar = '\t';

            doc.Save(writer);
            return strWriter.ToString();
        }
    }
}

   
    
  








Related examples in the same category

1.Get Formatted Xml
2.Clean Xml