I\'m trying to read in an XML configuration file, do a few tweaks (finding and removing or adding an element) and save it again. I want this edit to be as non-intrusive as possi
The LINQ to XML object model does not store whether an element parsed is marked up as
or
so when saving back such information is lost. If you want to ensure a certain format then you could extend an XmlWriter implementation and override its http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.writeendelement.aspx but that way you would also not preserve the input format, rather you would then write out any empty elements as
or whatever format you implement in your method.
There are other changes that can happen, for instance when loading the file
Example
Example
and saving it back the result is
Example
Example
so don't expect markup details to be preserved when loading/saving with XDocument/XElement.