Manipulating The HTML Tree
WWW projekt (wwwproj@dna.lth.se)
Mon, 22 Jul 1996 12:07:41 +0200
This talk concerns HTML::TreeBuilder and HTML::Element.
Fri, 19 Jul 1996 I wrote:
> I would like to have a method that can remove a a child and all of its
> subchilds in an elements contents.
>
> Is there an easy way of doing this today accessing $e->{'_content'}?
I would like to extend this discussion to how one should be able to
manipulate the HTML-tree in a comfortable way.
Today there is no way of inserting a new element in the tree, i.e.
inserting an element into a certain position in the contents of another
element.
Neither is there a way of deleting an element, as explained above.
If I want to do this today, I have to make a copy of the parents
contents, go through each element there to see if it is the element to
be deleted, and copy back those element that are not to be deleted.
It can be done with a 'grep' command, quite easily, even though it is
not very efficent.
"Whats the fuzz", you say, "you just said it can be done!"
Yes, I managed to do it alright, but as I was searching elements to
delete using the 'traverse' method, things messed up. The reason seems
to be that traverse cannot handle if the callback method manipulates the
contents.
I believe that HTML::Element needs two more methods, insert and remove
(or something like that) and that traverse needs to be rewritten so that
it can handle the problem above.
The reason that I have these ideas is, of course, that I am in desperate
need of these methods. Is there anybody out there that have any ideas
that might help me around these problems, please contact me.
---
Stefan Eriksson, Lund university, Sweden
wwwproj@dna.lth.se, dat93ser@ludat.lth.se