Click here to get back home

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

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
HTML::Element->right/->look_down lose, I need to walk the tree Roderick Schertler 06-20-2005
Get Chitika Premium
Posted by Roderick Schertler on June 20, 2005, 9:56 am
Please log in for more thread options


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

<html> @0
<head> @0.0
        <title> @0.0.0
         "HTML::Element test"
<body> @0.1
        <div> @0.1.0
         <h1> @0.1.0.0
         "heading"
        <p> @0.1.1
         "paragraph"

I've got to find the <p> after first searching for the <h1>. Because of
the <div> I can't use $h1->right. My first thought was to start from
$h1->pindex in $h1->parent->content_list, but this would fail if there
were even more levels between the two.

I really need to continue a walk of the tree, starting at h1. I can't
find an HTML::Element method which does that. It is an easy enough
iterator to write, but it seems so basic a need that I figure it's there and
I'm missing it. Is it?

It also seems to me that there should be something like ->look_down
(->look_next?) which does a search like this, for the same reason.

--
Roderick Schertler
roderick@argon.org


Posted by Terrence Brannon on September 5, 2005, 4:28 am
Please log in for more thread options



> Consider this HTML::Element dump of a simple HTML page:
>
> <html> @0
> <head> @0.0
>         <title> @0.0.0
>          "HTML::Element test"
> <body> @0.1
>         <div> @0.1.0
>          <h1> @0.1.0.0
>          "heading"
>         <p> @0.1.1
>          "paragraph"
>
> I've got to find the <p> after first searching for the <h1>.

you want a sibling of $tree->look_down('_tag' => 'h1') ;

if you use HTML::Element::Library on CPAN you can do this with easeeeee

> Because of the <div> I can't use $h1->right. My first thought was
> to start from
> $h1->pindex in $h1->parent->content_list, but this would fail if there
> were even more levels between the two.

you can always use look_up after looking down :)

> I really need to continue a walk of the tree, starting at h1. I can't
> find an HTML::Element method which does that. It is an easy enough
> iterator to write, but it seems so basic a need that I figure it's there and
> I'm missing it. Is it?
>
> It also seems to me that there should be something like ->look_down
> (->look_next?) which does a search like this, for the same reason.

again HTML::Element::Library contains all of my tree-grokking routines
+ the ones from Matthew Sisk's code for this HTML::Element hax

> >
> --
> Roderick Schertler
> roderick@argon.org

--
        Carter's Compass: I know I'm on the right track when,
         by deleting something, I'm adding functionality.


Similar ThreadsPosted
html interface to a data tree December 14, 2004, 7:24 am
Class::Tree V 1.24 July 29, 2004, 7:15 am
[RFC] XML::Simple::Tree November 3, 2005, 11:37 pm
a problem using Tree::DAG_Node? December 9, 2004, 2:44 pm
the use of removeChild() in Tree::Simple June 23, 2007, 8:18 am
querying modules dependency tree on CPAN November 19, 2004, 1:54 am
[RFC] HTML::Dashboard (Spreadsheet-like formatting for HTML tables) April 16, 2007, 4:50 pm
HTML ---> PDF October 27, 2004, 2:13 am
HTML::TableExtract October 11, 2004, 9:30 pm
[RFC] HTML::FormatData May 13, 2005, 2:51 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap