perlquestion
toma
In the pod for [cpan://XML::Filter::Dispatcher] is says:
<CODE>
## Print the text of all <description> elements
'string( description )' => sub { print xvalue },
</CODE>
My problem is that to get this to work I have to
write a full path to the description element, such
as <CODE>string( doc/head/description)</CODE> in
order to get the match. Also, it only matches the
first tag.<P>
Here is my full example, which is a slightly modified
example from the pod:
<READMORE><CODE>
use XML::Filter::Dispatcher qw ( :all );
use XML::SAX::Machines qw( Pipeline );
sub run { Pipeline( shift )->parse_string( <<XML_END ) }
<stooges>
<stooge name="Moe" hairstyle="bowl cut">
<attitude>Bully</attitude>
</stooge>
<stooge name="Shemp" hairstyle="mop">
<attitude>Klutz</attitude>
<stooge name="Larry" hairstyle="bushy">
<attitude>Middleman</attitude>
</stooge>
</stooge>
<stooge name="Curly" hairstyle="bald">
<attitude>Fool</attitude>
<stooge name="Shemp" repeat="yes">
<stooge name="Joe" hairstyle="bald">
<stooge name="Curly Joe" hairstyle="bald" />
</stooge>
</stooge>
</stooge>
</stooges>
XML_END
my $count;
run(
XML::Filter::Dispatcher->new(
Rules => [
'stooge' => sub { ++$count },
'string( stooges/stooge/attitude )' => sub { print xvalue(),"\n"; },
],
)
);
</CODE>
This prints the contents of only one <attitude>
tag, and I want it to match all of them.
When I substitute <BR>
<CODE>
'string( attitude )' => sub { print xvalue; },
</CODE><BR>
as the pod seems to suggest, it no longer prints anything.
Am I doing something wrong?<P>
I already have something like this working in [cpan://XML::Twig],
so I can always go back to that.<P>
Thanks!
<P><I>It should work perfectly the first time! - toma</I>