Outputs:use strict; use warnings; use HTML::TreeBuilder; my $html = '<h1>Blah</h1> <p> <br> <h2>Blah</h2>'; my $element_root = HTML::TreeBuilder->new_from_content($html); $element_root->dump; print "\n"; $element_root->splice_content(1,1); $element_root->dump;
UPDATE: Thanks to everyone below. Practically every suggestion was useful. In the end, I realized that the main mistake I was making was doing the splice from the root node, rather than the body. I'm still not 100% satisfied, but at least now the splice works. The code I'm using now is:<html> @0 (IMPLICIT) <head> @0.0 (IMPLICIT) <body> @0.1 (IMPLICIT) <h1> @0.1.0 "Blah" " á" <p> @0.1.2 "á" <br> @0.1.2.1 <h2> @0.1.3 "Blah" <html> @0 (IMPLICIT) <head> @0.0 (IMPLICIT)
use strict; use warnings; use HTML::Treebuilder; my $html = '<h1>Blah</h1> <p> <br> <h2>Blah</h2>'; my $element_root = HTML::TreeBuilder->new_from_content($html); my $body = $element_root->look_down( _tag => "body"); $body->dump; print "\n"; $body->splice_content(1,2); $body->dump;
In reply to Help with HTML::Element->splice_content by tphyahoo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |