That sort of utility is best written as a filter so things can be piped in and out:
GenerateSomeXml | MakePretty | SomethingElse
GenerateSomeXml | MakePretty > outfile
type infile | MakePretty > outfile
And you can have it take parameters optionally as well to add flexibility.
As for the basic implementation, I prefer:
System.Xml.XmlDocument doc = new System.Xml.XmlDocument() ;
doc.LoadXml ( System.Console.In.ReadToEnd() ) ;
System.Xml.XmlWriterSettings xs = new System.Xml.XmlWriterSettings() ;
xs.Indent = true ;
using
(
System.Xml.XmlWriter xw
=
System.Xml.XmlWriter.Create ( System.Console.Out , xs )
)
{
doc.WriteTo ( xw ) ;
}
An important note on XmlWriter is that you must remember to use
using
or
Flush
.