java - Jsoup cleaning my html -
i'm trying learn how use jsoup cleaning html code.
i want remove <body>
tag example <p>
tag must stay:
public class prb { public static void main(string[] args) throws exception { string = "<p>text 1234 <body>wow</body> text 1234</p><p>text 1234</p>"; system.out.println(getstringwithouthtmltags(i)); } public static string getstringwithouthtmltags(string text) { whitelist asd = new whitelist(); asd.addtags("<p>", "</p>"); asd.removetags("<body>, </body>"); return jsoup.clean(text, asd); } }
but removes tags. output is:
text 1234 wow text 1234 text 1234
what doing wrong?
thank in advance.
you made mistake on writing tags
, because asd.addtags("<p>", "</p>");
heavy because have twice p
, <,>,/
useless
so documentation says :
asd.addtags("p"); asd.removetags("body");
more details on tags/attributes/procotols whitelist : jsoup whitelist
Comments
Post a Comment