StringEscapeUtils.escapeXml is converting utf8 characters which it should not

Mady picture Mady · Jan 24, 2012 · Viewed 21.8k times · Source

escapeXml function is converting ѭ Ѯ to ѭ Ѯ which I guess it should not. What I read is that it Supports only the five basic XML entities (gt, lt, quot, amp, apos).

Is there a function that only converts these five basic xml entities?

Answer

Bombe picture Bombe · Jan 24, 2012
public String escapeXml(String s) {
    return s.replaceAll("&", "&amp;").replaceAll(">", "&gt;").replaceAll("<", "&lt;").replaceAll("\"", "&quot;").replaceAll("'", "&apos;");
}