Convert HTML-escaped strings to plain Unicode/ASCII

android, html, java

Solution

Use this:

import org.apache.commons.lang.StringEscapeUtils;

public class StringEscapeUtilsTrial {
public static void main(String[] args) {
    String strHTMLInput = "<p>MyName<p>";
    String strEscapeHTML = StringEscapeUtils.escapeHtml(strHTMLInput);
    String strUnEscapeHTML = StringEscapeUtils.unescapeHtml(strEscapeHTML);
    System.out.println("Escaped HTML >>> " + strEscapeHTML);
    System.out.println("UnEscaped HTML >>> " + strUnEscapeHTML);
    }
}

Problem

Possible Duplicate: Java: How to decode HTML character entities in Java like HttpUtility.HtmlDecode? is there a Java/Android way to convert HTML-escaped strings (such as `&Ouml;` or `&szlig;`) back to their ASCII/Unicode representations (such as `Ö` or `ß`)? I of course do not want to do a simple string-replacement and try with just every HTML-escape-sequence that exists, I'd guess there is a ready-to use solution? Thanks!

Original source

Related problems