문제

...<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