Hi,
I have to do some cleanup of HTML code based on some conditions. I need to remove all <img> for example.
I have gone through couple of related issues which talks about removing tags.
I tried doing the same, but does not work. Could anyone point out the right way of doing this?
NodeList list = ndList.extractAllNodesThatMatch(new TagNameFilter("img"), true); for (int i = 0; i < list.size(); i++) { Node nd = list.elementAt(i); nd.getParent().getChildren().remove(nd); }
This ends up removing only the first img tag. All remaining ones are not getting removed.
Any help will be appreciated. Thanks
Sorry for the trouble,
It works fine.
Log in to post a comment.
Hi,
I have to do some cleanup of HTML code based on some conditions. I need to remove all <img> for example.
I have gone through couple of related issues which talks about removing tags.
I tried doing the same, but does not work. Could anyone point out the right way of doing this?
NodeList list = ndList.extractAllNodesThatMatch(new TagNameFilter("img"), true);
for (int i = 0; i < list.size(); i++) {
Node nd = list.elementAt(i);
nd.getParent().getChildren().remove(nd);
}
This ends up removing only the first img tag. All remaining ones are not getting removed.
Any help will be appreciated. Thanks
Sorry for the trouble,
It works fine.