Basically I would like to decode a given Html document, and replace all special chars, such as " " -> " ", ">" -> ">".
In .NET we can make use of HttpUtility.HtmlDecode.
What's the equivalent function in Java?
Basically I would like to decode a given Html document, and replace all special chars, such as " " -> " ", ">" -> ">".
In .NET we can make use of HttpUtility.HtmlDecode.
What's the equivalent function in Java?
I have used the Apache Commons StringEscapeUtils.unescapeHtml4() for this:
Unescapes a string containing entity escapes to a string containing the actual Unicode characters corresponding to the escapes. Supports HTML 4.0 entities.
If you're using Spring framework already, use the following method:
import static org.springframework.web.util.HtmlUtils.htmlUnescape;
...
String result = htmlUnescape(source);
StringEscapeUtils (Apache Commons Lang)
Escapes and unescapes Strings for Java, JavaScript, HTML, and XML.
import org.apache.commons.lang.StringEscapeUtils;
....
StringEscapeUtils.unescapeHtml(comment);