develooper Front page | perl.libwww | Postings from January 2002

HTML::Element -- printing just one path through tree

Bill Moseley
January 10, 2002 16:28
HTML::Element -- printing just one path through tree
Message ID:

I traverse a parse tree looking for a specific node (it's a converted text
content e.g. ~text).  I then want to print the entire tree, but only the
path that leads to this text segment.

In simpler terms:

  <b>I <em>traverse</em> just <em>a <big>parse</big> tree</em> looking</b>

So I traverse down looking for "parse".  When I find it I want to generate:


The problem is that I want to leave the tree intact.  

I could recursively follow $h->lineage, and remove any content that's not
pointing to the current node (child), but that destroys my tree.  

I can't clone the entire tree, as I'm not sure where I'm starting from.

I guess I could recursively move up the lineage, store each parent's
content list in some new attribute 

    $parent->{content_save} = [$parent->content_list];

grab $root->as_HTML, then work my way back down the tree fixing each node's
content list along the way.

Hum, is there an easier way?

Bill Moseley Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About