Change encoding from utf-8 to UTF-8

Hello all,
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:

  1. Read text file
  2. Deserialize XML to xml document
  3. Set attributes with values
  4. Invoke method save on xml document
    Here comes the remediation steps:
  5. Read xml file again using read text file
  6. replace utf-8 with UTF-8
  7. write text file
    Isn’t there a more elegant way to solve this?

manipulating the encoding string without proper saving the file with changed encoding can cause side effects. But I assume that you already know this.

Give a try:

  • interacting with the Prolog.Encoding Property:

or Do a play with with the writers and change the encoding of the writers

1 Like