using System;
using System.IO;
using System.Text;
using System.Xml;

namespace Earthblend.Tts.Common.Core.Extentions
{
    public static partial class UniqueExtensions
    {
        public static String FormatXml(this String xml)
        {
            String Result = "";

            MemoryStream MS = new MemoryStream();
            XmlTextWriter W = new XmlTextWriter(MS, Encoding.Unicode);
            XmlDocument D = new XmlDocument();

            try
            {
                D.LoadXml(xml);
                W.Formatting = Formatting.Indented;
                D.WriteContentTo(W);
                W.Flush();
                MS.Flush();
                MS.Position = 0;
                StreamReader SR = new StreamReader(MS);
                String FormattedXML = SR.ReadToEnd();
                Result = FormattedXML;
            }
            catch (XmlException)
            {
            }


            MS.Close();
            //W.Close();
            W = null;

            return Result;
        }
    }
}