I have a requirement where I need to save an XML file with encoding set capitalized to “UTF-8” instead of utf-8. For some reason, when you deserialize an XML document it sets the encoding to lower case. So UTF-8 becomes utf-8. This seems a bug to me.
Here is the solution I have for now:
- Read text file
- Deserialize XML to xml document
- Set attributes with values
- Invoke method save on xml document
Here comes the remediation steps:
- Read xml file again using read text file
- replace utf-8 with UTF-8
- write text file
Isn’t there a more elegant way to solve this?