using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace Hcs.WebApp.Utils
{
    internal static class XmlBeautifier
    {
        internal static string Beautify(string xml)
        {
            var stringBuilder = new StringBuilder();

            var settings = new XmlWriterSettings
            {
                OmitXmlDeclaration = true,
                Indent = true,
                NewLineOnAttributes = true
            };

            using (var xmlWriter = XmlWriter.Create(stringBuilder, settings))
            {
                var element = XElement.Parse(xml);
                element.Save(xmlWriter);
            }

            return stringBuilder.ToString();
        }
    }
}
