This question already has an answer here:
String s = "This — That"; .... document.appendChild(document.createTextNode(s)); .... transformer.transform(new DOMSource(document), new StreamResult(stringWriter)); System.out.println(stringWriter.toString()); // outputs "This — That" at the relevant Node.
I have no control over the input string and I need exactly the output "This — That".
If I use StringEscapeUtils.unescapeHtml the output is "This — That", but I need to preserve its representation as an entity. I have tried several versions of transformer.setOutputProperty(OutputKeys.ENCODING, "encoding") but haven't found the one that converts "—" to "—"
What can I do to prevent javax.xml.transform.Transformer from re-escaping already correctly escaped text or how can I transform the input to get entities in the output?
No comments:
Post a Comment