I use an XmlDocument.WriteTo(XmlWriter)
method to serialize an XmlDocument
to a text file. I have also tried XmlDocument.OuterXml
. Both output a single-line XML text which is very hard (up to impossible in case of a reasonably big XML document) to read for a human.
Is there a way to output a well-formatted human-readable XML text instead? I mean with every element starting at a new line and indentation used to visualize hierarchy levels.
I agree to BoltClock. Here is the sample code-
//Create a writer to write XML to the console.
XmlTextWriter writer = null;
writer = new XmlTextWriter (Console.Out);
//Use indentation for readability.
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
If you're using XmlTextWriter
to write to the file, you can set its Formatting
property to Formatting.Indented
before you write.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With