Since this is a line, adding line breaks and indentation will change the actual value of the xml variable, which is not what you want your code formatter to do!
Note that you can format XML in C # before writing to the page, for example:
using System; using System.IO; using System.Text; using System.Xml; namespace XmlIndent { class Program { static void Main(string[] args) { string xml = "<doc><object><first>Joe</first><last>Smith</last></object></doc>"; var xd = new XmlDocument(); xd.LoadXml(xml); Console.WriteLine(FormatXml(xd)); Console.ReadKey(); } static string FormatXml(XmlDocument doc) { var sb = new StringBuilder(); var sw = new StringWriter(sb); XmlTextWriter xtw = null; using(xtw = new XmlTextWriter(sw) { Formatting = Formatting.Indented }) { doc.WriteTo(xtw); } return sb.ToString(); } } }
source share