javaxmlstringescapeutils

StringEscapeUtils.escapeXml is converting utf8 characters which it should not


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?


Solution

  • public String escapeXml(String s) {
        return s.replaceAll("&", "&amp;").replaceAll(">", "&gt;").replaceAll("<", "&lt;").replaceAll("\"", "&quot;").replaceAll("'", "&apos;");
    }