Menu

Removing a bunch of tags

Help
2008-07-08
2013-04-27
  • Anand Viswanath

    Anand Viswanath - 2008-07-08

    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

     
    • Anand Viswanath

      Anand Viswanath - 2008-07-10

      Sorry for the trouble,

      It works fine.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.