You should be able to prevent escaping by:
Extending
XMLOutputer
and overridingescapeElementEntities
methodXMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()) { @Override public String escapeElementEntities(String str) { return str; } }; Writer writer = new OutputStreamWriter(new FileOutputStream(file), "utf-8"); outputter.output(doc, writer); writer.close();
I found this here
- Setting custom
EscapeStrategy
on theFormat
to prevent escaping certain characters
Either way you should be careful to produce a valid XML.
Hope this helps.