transformer.setOutputProperty(OutputKeys.ENCODING, “UTF-8”) is NOT working
I had the same problem on Android when serializing emoji characters. When using UTF-8 encoding in the transformer the output was HTML character entities (UTF-16 surrogate pairs), which would subsequently break other parsers that read the data. This is how I ended up solving it: StringWriter sw = new StringWriter(); sw.write(“<?xml version=\”1.0\” encoding=\”UTF-8\” ?>”); Transformer … Read more