Gisle Aas <[EMAIL PROTECTED]> writes:

> You need to ask for something to be reported for text.  This is an
> expanded sample:

I actually wanted to use this example (which also shows what @attr)
expands to and use defined() test on the while loop in order to avoid
that text like "0" terminate the loop.

-------------------------------------------------------------------
use HTML::PullParser;
use Data::Dump qw(dump);

$doc = <<'EOT';
<TITLE>&lt;Foo&gt;</TITLE>
<script>
<foo>
</script>

<h1>Hi <a href="#dude">dude</a></h1>
EOT

my $p = HTML::PullParser->new(doc => $doc,
                              start => 'event,tagname,@attr',
                              end   => 'event,tagname',
                              text  => '@{dtext}',
                              unbroken_text => 1,
                              ignore_elements => ['script'],
                             );

while (defined(my $t = $p->get_token)) {
    print dump($t), "\n";
}
-------------------------------------------------------------------
Output:

["start", "title"]
"<Foo>"
["end", "title"]
"\n\n\n"
["start", "h1"]
"Hi "
["start", "a", "href", "#dude"]
"dude"
["end", "a"]
["end", "h1"]
"\n"

Reply via email to