Preserve xml formatting using XmlDocument
I am using XmlDocument to work with xml How do I save my "XmlDocument" with my current formatting? Current formatting: <?xml version="1.0" encoding="utf-8"?> <root> <element></element> </root> Code: XmlDocument testDoc = new XmlDocument(); testDoc.Load(@"C:\Test.xml"); **(do reading/writing using only XmlDocument methods)** testDoc.Save(@"C:\Test.xml"); There is a similar topic: XmlDocument class is removing formatting, c#, .NET The accepted answer is PreserveWhiteSpace = true, which in reality removes all whitespaces instead of preserving them. Example: Code: XmlDocument testDoc = new