in reply to Re^2: Truncating an HTML node using XPaths in HTML::TreeBuilder::XPath
in thread Truncating an HTML node using XPaths in HTML::TreeBuilder::XPath
A tip for tips is to look around a tip, both above and below :)
#!/usr/bin/perl -- use strict; use warnings; use HTML::TreeBuilder::XPath; my $tree= HTML::TreeBuilder::XPath->new_from_content(<<'HTML'); <body> <div><p>foo01<br />bar01</p></div> <div> <p> foo02 <br /> bar02 </p> </div> <div> <p> foo03 <br /> bar03 <br / baz03 </p> </div> HTML # $tree->dump; print $tree->as_HTML( '><&' => " " ), "\n";; for my $br ( $tree->findnodes( '//div/p/br[1]' ) ){ $br->parent->splice_content( $br->pindex, int@{ $br->parent->content_array_ref } ); } # $tree->dump; print $tree->as_HTML( '><&' => " " ), "\n";; __END__ <html> <head> </head> <body> <div> <p>foo01<br />bar01</div> <div> <p> foo02 <br /> bar02 </div> <div> <p> foo03 <br /> bar03 <br </p="</p" baz03="baz03" /> </div> </body> </html> <html> <head> </head> <body> <div> <p>foo01</div> <div> <p> foo02 </div> <div> <p> foo03 </div> </body> </html>
|
|---|