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






Clean Xml

  
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Xsl;
using System.Web.UI;

namespace ARF.Web.Utility
{
    public class Utility
    {
        public static void CleanXml(XmlDocument xml)
        {
            XmlTextReader oReader = new XmlTextReader(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("ARF.Resources.CleanXml.xsl"));
            XslCompiledTransform oTransform = new XslCompiledTransform();
            oTransform.Load(oReader);

            System.IO.StringWriter sw = new System.IO.StringWriter();

            XmlTextWriter writer = new XmlTextWriter(sw);
            oTransform.Transform(xml, null, writer);
            xml.LoadXml(sw.ToString());
        }

        public static XmlDocument CleanXml(string xml)
        {
            XmlDocument oDoc = new XmlDocument();
            oDoc.LoadXml(xml);
            CleanXml(oDoc);
            return oDoc;
        }

    }
}

   
    
  








Related examples in the same category

1.Get Formatted Xml
2.Format Xml