I am creating a lightweight editor in C# and would like to know the best method for converting a string into a nicely formatted XML string. I would hope that there\'s a pub
In Framework 4.0 it is simple.
var unformattedXml = "Lewis, C.S. The Four Loves ";
var xdoc = System.Xml.Linq.XDocument.Parse(unformattedXml);
var formattedXml = (xdoc.Declaration != null ? xdoc.Declaration + "\r\n" : "") + xdoc.ToString();
Console.WriteLine(formattedXml);
This adds in the required indentation, and maintains the Xml Declaration.
Lewis, C.S.
The Four Loves