Projelerde bazen xml dokümanını formatlı göstermeniz gerekebilir.Aşağıdaki kod parçası içine string tipinde verdiğiniz xml dokumanını formatlayarak gösterir.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;
using System.IO;
using System.Text;

///
/// Summary description for Utility
///

public static class Utility
{

public static string XmlFormat(string input)
{
XmlDocument document = new XmlDocument();
document.Load(new StringReader(input));

StringBuilder strbuilder = new StringBuilder();
using (XmlTextWriter writer = new XmlTextWriter(new StringWriter(strbuilder)))
{
writer.Formatting = Formatting.Indented;
document.Save(writer);
}

return builder.ToString();
}
}