5

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 Ö or ß) 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!

Community
  • 1
  • 1
Elmi
  • 5,581
  • 13
  • 63
  • 132

1 Answers1

10

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);
    }
}
Harish Raj
  • 1,527
  • 3
  • 16
  • 25