Mega Code Archive

 
Categories / C# / XML
 

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();         }     } }