0
...<b><a>hello</a></b>...

I'd like to remove the <b></b> tags from the html document. Is it possible using Jsoup?

Terry Li
  • 16,870
  • 30
  • 89
  • 134

2 Answers2

0
public String clean(String unsafe){ 
        Whitelist whitelist = Whitelist.none(); 
        whitelist.addTags(new String[]{"a"}); 

        String safe = Jsoup.clean(unsafe, whitelist); 
        return StringEscapeUtils.unescapeXml(safe); 
 } 

From Removing Html tags except few specific ones from String in java

Community
  • 1
  • 1
David Houde
  • 4,835
  • 1
  • 20
  • 29
0

If doc is your Document containig your HTML:

doc.select("b").unwrap();

(can be used with Element / Elements too)

Example:

Document document = new Document("");
document.html("...<b><a>hello</a></b>...").select("b").unwrap();

Now your document doesn't contain any b-Tag

ollo
  • 24,797
  • 14
  • 106
  • 155