I have a XML File where i have to replace a single value of an element. For this im loading my XML file into a XDocument: var camtXml = XDocument.Load(fileStream); After im done with my changes and saving the XDocument to a file there are multiple changes that shouldn't be done. As you can see in the following picture (Left side file from XDocument, rigth site original file):

The UTF-8 was changed from upper- to lower case, CR Linefeeds were added and the indentation has been changed by removing withespaces. I really wan't to use XDocument because of its libary what easily allows to create and iterate through XElements. But the formatting changes are a show stopper. Is there a way to preserve these formatting changes or is there an alternativ to XDocument with the same options like XPath, XElement etc.? I found this but it didn't solved my problem. XDocument how to save without Byte Order Mark AND preseve formatting/whitespace