I am writing a tool that takes in an XML file, edits it by adding in elements and then saves it. The tricky bit is that the XML files need to be maintained human readable, and in this case that doesn't mean perfect formatting.
The input XElement contains many parameters such as this:
<Parameter key="lorem"> <Vector> <Value>2</Value><Value>3</Value> </Vector> </Parameter>
<Parameter key="lorem"> <Vector> <Value>2</Value><Value>3</Value> </Vector> </Parameter>
<Parameter key="lorem"> <Vector> <Value>2</Value><Value>3</Value> </Vector> </Parameter>
<Parameter key="lorem"> <Vector> <Value>2</Value><Value>3</Value> </Vector> </Parameter>
<Parameter key="lorem">
<Parameter key="ipsum">
<Parameter key="dolor">
<Vector> <Value>3</Value> <Value>4</Value> </Vector>
</Parameter>
</Parameter>
</Parameter
I want all XElements with name "Vector" and "Value" to disable indenting, but all XElements with name "Parameter" to maintain indenting.
Since my code isn't allowed to mess up any of the existing formatting, I am forced to use LoadOptions.PreserveWhitespace on the source document. This, however, forces all XElements that I add to the document to loose any formatting. Is there a way I can force a particular XElement to apply formatting, even though the whole document doesn't do it?