Is there a method in the .NET Framework or a free Open Source library to pretty print XML?
+4
A:
All of .Net's standard XML APIs will format their output.
Using LINQ to XML:
string formatted = XDocument.Parse(source).ToString();
Or
string formatted = XDocument.Load(path).ToString();
SLaks
2010-06-17 15:22:46
Worked like a charm. Many thanks.
Josh Kodroff
2010-06-17 21:49:54
+2
A:
Use the XmlWriterSettings with an XmlWriter
var doc = new XmlDocument();
doc.Load(@"c:\temp\asdf.xml");
var writerSettings = new XmlWriterSettings
{
Indent = true,
NewLineOnAttributes = true,
};
var writer = XmlWriter.Create(@"c:\temp\asdf_pretty.xml", writerSettings);
doc.Save(writer);
simendsjo
2010-06-17 15:31:00
A:
You can use XMLBuilder to generate the XML and then call ToString method to get a indented output.
ararog
2010-06-17 16:09:20