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,899
  • 15
  • 72
  • 143

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,565
  • 3
  • 17
  • 27