jai_dgl has asked for the wisdom of the Perl Monks concerning the following question:

I am using HTML::DOM module in perl, my requirement is, I have to traverse the enitre DOM and find <img> tag and remove <img> where ever its found in the HTML. please help me to traverse the DOM and find a specified tag and delete it. Thanks

Replies are listed 'Best First'.
Re: HTML::DOM traverse
by holli (Abbot) on Apr 14, 2008 at 10:18 UTC
Re: HTML::DOM traverse
by ikegami (Patriarch) on Apr 14, 2008 at 10:34 UTC

    If you're intent is to sanitize HTML submitted by your users, I'm don't think HTML::DOM (or any other module that constructs a tree from the HTML before doing anything else) is the right route.

    If not, here's what you asked:

    for my $img ( $dom_tree->getElementsByTagName('img') ) { $img->delete(); }

    Untested. Assumes getElementsByTagName returns HTML::Element objects.

      Thanks its Working great.