If you want to do something about formatting of the output XML document, I
think you should focus on the XmlWriter (such as XmlTextWriter) since
XmlWriter is the underlying component that dedicated to XML document
writeout and persist. XmlDocument (DOM api class) is only responsible for
constructing XMLDocument structure rather than formatting.
Also, for add custom formatting, I have a suggestion on create a custom
XmlWriter, you can derive your custom XmlWriter class from XmlTextWriter
For example, you can consider override one of the methods such as
"WriteEndElement" and add some additional whitespace string there. And at
runtime, whenever you want to save or writeout any XmlDocument(or directly
using XmlWriter), use your custom xmlWriter to wrapper the original writer.
Microsoft MSDN Online Support Lead
Get notification to my posts through email? Please refer to
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
This posting is provided "AS IS" with no warranties, and confers no rights.