I'd like to process an XHTML document and remove certain types of nodes if they are blank. I've started trying to do that with HTML::TreeBuilder::XPath and seem to find the I want to remove. The following subroutine finds them just fine but appears to fail to delete the found empty nodes:
sub readthefile { my ($file)= (@_); print qq(File=$file\n); my $xhtml = HTML::TreeBuilder::XPath->new; $xhtml->implicit_tags(1); $xhtml->parse_file($file) or die("Could not parse '$file' : $!\n"); for my $list ($xhtml->findnodes('/html/body//div/ul/li')) { if($list->is_empty) { print qq(DELETE\n); $list->delete(); # this line does not do what I thought it + would :( } } print $xhtml->as_XML_indented; $xhtml->delete; return (1); }
As it is, the routine just prints out "DELETE" the right number of times but then at the end still prints the unmodified original XHTML. How do I excise the chosen nodes from the final output if they are empty?
In reply to Deleting nodes with HTML::TreeBuilder::XPath by mldvx4
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |