To do this, you'll have to use something more sophisticated than a StreamSource. For example, a StAXSource takes an XMLStreamReader, which has the getCharacterEncodingScheme() method that tells you which encoding the input document used - you can the set that as output enocding.
Read full article from java - How to Preserve the Input's Declared Encoding in the Output of javax.xml.transform.Transformer.transform? (e.g. avoid UTF-16 changing to UTF-8) - Stack Overflow
No comments:
Post a Comment