I meet a position when i using jsoup to extracting data. The data like this:
This is a strong number 2013
This should answer your question :
public String escapeHtml(String source) {
Document doc = Jsoup.parseBodyFragment(source);
Elements elements = doc.select("b");
for (Element element : elements) {
element.replaceWith(new TextNode(element.toString(),""));
}
return Jsoup.clean(doc.body().toString(), new Whitelist().addTags("a").addAttributes("a", "href", "name", "rel", "target"));
}
Jsoup - Howto clean html by escaping not deleting the unwanted html?