Andreas Koenig wrote:
>
> www> Note the $ele->tag("noop"); line, he sets the tag to be 'noop'
> www> and it will stay in the tree, but as an unknown tag NOOP.
>
> The NOOP was intentional, not an unfortunate effect. $ele->delete
> works just fine for real deletes. The NOOP is there, so I do not
> censor what the people wrote, but prevent them from breaking the
> guestbook page. $self->{HTML_OK} allows e.g. UL, OL, A, LI, and some
> such. If they come with IMG, they get what they deserve :-) But I
> still can see, what they tried to do.
Ok, I can see that now. I will explain why I misunderstood the code
later.
> www> I still think that a 'remove' method should me implemented that
> www> really removes the element from the tree, but it might be a bit
> www> tricky because of the use of arrays instead of linked lists in
> www> the structure.
>
> Sorry, can't follow you. Why does ->delete() not do what you want?
Because the tag is not deleted from the tree:
~/Stefan/tmp>perl -w -MHTML::TreeBuilder
$html = '<I> Italic </I> <B> Bold </B> <HR>';
$p = new HTML::TreeBuilder;
$p->parse($html);
$p->traverse(sub {
my ($ele, $flag, $depth) = @_;
if ($ele->tag eq 'b') {
$ele->delete();
}
return 1;
}, 1);
print "---------\n", $p->as_HTML, "--------\n";
$p->traverse(sub {
my ($ele, $flag, $depth) = @_;
return unless $flag;
print $ele->tag, " printing parent tag: ";
if ($ele->tag ne 'html') {
print $ele->parent->tag;
}
print "\n";
return 1;
}, 1);
---------
Italic
Bold paragraph
inbetween the hr and br tags in this tree:
Can you do this in a way that excludes the risk of errors and that does
not depend on the type of tags that are inserted or surround the
inserted tag?
---
Stefan Eriksson, Lund university, Sweden
wwwproj@dna.lth.se, dat93ser@ludat.lth.se