tphyahoo has asked for the wisdom of the Perl Monks concerning the following question:
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help with HTML::Element->splice_content
by gu (Beadle) on Dec 02, 2005 at 19:00 UTC | |
|
Re: Help with HTML::Element->splice_content
by santonegro (Scribe) on Dec 02, 2005 at 21:16 UTC | |
|
Re: Help with HTML::Element->splice_content
by santonegro (Scribe) on Dec 02, 2005 at 23:36 UTC | |
|
Re: Help with HTML::Element->splice_content
by santonegro (Scribe) on Dec 02, 2005 at 21:32 UTC | |
by tphyahoo (Vicar) on Dec 06, 2005 at 14:37 UTC |