What is the simplest way to get indented XML with line breaks from XmlDocument?

Based on the other answers, I looked into XmlTextWriter and came up with the following helper method: static public string Beautify(this XmlDocument doc) { StringBuilder sb = new StringBuilder(); XmlWriterSettings settings = new XmlWriterSettings { Indent = true, IndentChars = ” “, NewLineChars = “\r\n”, NewLineHandling = NewLineHandling.Replace }; using (XmlWriter writer = XmlWriter.Create(sb, settings)) … Read more

XDocument or XmlDocument

If you’re using .NET version 3.0 or lower, you have to use XmlDocument aka the classic DOM API. Likewise you’ll find there are some other APIs which will expect this. If you get the choice, however, I would thoroughly recommend using XDocument aka LINQ to XML. It’s much simpler to create documents and process them. … Read more