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
string unformattedXml = "Lewis, C.S. The Four Loves ";
string formattedXml = XElement.Parse(unformattedXml).ToString();
Console.WriteLine(formattedXml);
Output:
Lewis, C.S.
The Four Loves
The Xml Declaration isn't output by ToString(), but it is by Save() ...
XElement.Parse(unformattedXml).Save(@"C:\doc.xml");
Console.WriteLine(File.ReadAllText(@"C:\doc.xml"));
Output:
Lewis, C.S.
The Four Loves