HTML::Element->right/->look_down lose, I need to walk the tree

HTML::Element->right/->look_down lose, I need to walk the tree

am 20.06.2005 14:56:54 von Roderick Schertler

Consider this HTML::Element dump of a simple HTML page:

@0
@0.0
@0.0.0<br /> "HTML::Element test"<br /> <body> @0.1<br /> <div> @0.1.0<br /> <h1> @0.1.0.0<br /> "heading"<br /> <p> @0.1.1<br /> "paragraph"<br /> <br /> I've got to find the <p> after first searching for the <h1>. Because of<br /> the <div> I can't use $h1->right. My first thought was to start from<br /> $h1->pindex in $h1->parent->content_list, but this would fail if there<br /> were even more levels between the two.<br /> <br /> I really need to continue a walk of the tree, starting at h1. I can't<br /> find an HTML::Element method which does that. It is an easy enough<br /> iterator to write, but it seems so basic a need that I figure it's there and<br /> I'm missing it. Is it?<br /> <br /> It also seems to me that there should be something like ->look_down<br /> (->look_next?) which does a search like this, for the same reason.<br /> <br /> -- <br /> Roderick Schertler<br /> roderick@argon.org</p> </article> <article> <h2>Re: HTML::Element->right/->look_down lose, I need to walk the tree</h2><span>am 05.09.2005 06:28:53 von Terrence Brannon</span> <p>Roderick Schertler <roderick@argon.org> writes:<br /> <br /> > Consider this HTML::Element dump of a simple HTML page:<br /> ><br /> > <html> @0<br /> > <head> @0.0<br /> > <title> @0.0.0<br /> > "HTML::Element test"<br /> > <body> @0.1<br /> > <div> @0.1.0<br /> > <h1> @0.1.0.0<br /> > "heading"<br /> > <p> @0.1.1<br /> > "paragraph"<br /> ><br /> > I've got to find the <p> after first searching for the <h1>.<br /> <br /> you want a sibling of $tree->look_down('_tag' => 'h1') ;<br /> <br /> if you use HTML::Element::Library on CPAN you can do this with easeeeee<br /> <br /> > Because of the <div> I can't use $h1->right. My first thought was<br /> > to start from<br /> > $h1->pindex in $h1->parent->content_list, but this would fail if there<br /> > were even more levels between the two.<br /> <br /> you can always use look_up after looking down :)<br /> <br /> > I really need to continue a walk of the tree, starting at h1. I can't<br /> > find an HTML::Element method which does that. It is an easy enough<br /> > iterator to write, but it seems so basic a need that I figure it's there and<br /> > I'm missing it. Is it?<br /> ><br /> > It also seems to me that there should be something like ->look_down<br /> > (->look_next?) which does a search like this, for the same reason.<br /> <br /> again HTML::Element::Library contains all of my tree-grokking routines<br /> + the ones from Matthew Sisk's code for this HTML::Element hax<br /> <br /> > ><br /> > -- <br /> > Roderick Schertler<br /> > roderick@argon.org<br /> <br /> -- <br /> Carter's Compass: I know I'm on the right track when,<br /> by deleting something, I'm adding functionality.</p> </article> <footer> <a href="/">Index</a> | <a href="/impressum.php">Impressum</a> | <a href="/datenschutz.php">Datenschutz</a> | <a href="https://www.xodox.de/">XODOX</a> </footer> </main> </body> </html>