Android Utililty Methods XML String Unescape

List of utility methods to do XML String Unescape

Description

The list of methods to do XML String Unescape are organized into topic(s).

Method

StringxmlUnescape(String xml)
Notice that this function only escape entity reference and not character reference.
return xml.replaceAll("&lt;", "<").replaceAll("&gt;", ">")
        .replaceAll("&quot;", "\"").replaceAll("&apos;", "'")
        .replaceAll("&amp;", "&");
Stringunescape(String input)
Useful to replace the escaped characters their unescaped counterparts Ex: &amp; -> &
return input.replace("&amp;", "&").replace("&lt;", "<")
        .replace("&gt;", ">").replace("&quot;", "\"")
        .replace("&apos;", "\'");
Stringunescape(String source)
unescape
for (char unescape_symbol : unescape_symbols) {
    source = source.replaceAll(
            String.format("&#%s;", (int) unescape_symbol),
            unescape_symbol + "");
return source;
StringunescapeXML(final String xml)
unescape XML
Pattern xmlEntityRegex = Pattern.compile("&(#?)([^;]+);");
StringBuffer unescapedOutput = new StringBuffer(xml.length());
Matcher m = xmlEntityRegex.matcher(xml);
Map<String, String> builtinEntities = null;
String entity;
String hashmark;
String ent;
int code;
...
StringurlEscape(String s)
Do a simple RFC2396 encoding
s = s.replace("%", "%25");
s = s.replace(" ", "%20");
s = s.replace("!", "%21");
s = s.replace("\"", "%22");
s = s.replace("#", "%23");
s = s.replace("$", "%24");
s = s.replace("&", "%26");
s = s.replace("'", "%27");
...
StringreplaceEscape(String result)
replace Escape
if (result == null) {
    return "";
result = result.replace("\\n", "\n");
result = result.replace("&apos;", "'");
result = result.replace("&quot;", "\"");
result = result.replace("apos;", "'");
result = result.replace("quot;", "\"");
...
StringreplaceEscapeSequence(String input)
replace Escape Sequence
String output = null;
if (input != null) {
    output = input.replaceAll("&lt;", "<");
    output = output.replaceAll("&gt;", ">");
    output = output.replaceAll("&amp;", "&");
    output = output.replaceAll("&apos;", "??");
    output = output.replaceAll("&quot;", "\"");
return output;
Stringunescape(String text)
Unescaping some chars and symbols
return text.replace("&amp;", "&").replace("&quot;", "\"")
        .replace("<br>", "\n").replace("&gt;", ">")
        .replace("&lt;", "<").replace("&#39;", "'")
        .replace("<br/>", "\n").replace("&ndash;", "-")
        .replace("&#33;", "!").trim();