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

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

有帮助吗?

解决方案

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

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top