toma has asked for the wisdom of the Perl Monks concerning the following question:
In the pod for XML::Filter::Dispatcher is says:
as the pod seems to suggest, it no longer prints anything. Am I doing something wrong?
My problem is that to get this to work I have to write a full path to the description element, such as string( doc/head/description) in order to get the match. Also, it only matches the first tag.## Print the text of all <description> elements 'string( description )' => sub { print xvalue },
Here is my full example, which is a slightly modified example from the pod:
This prints the contents of only one <attitude> tag, and I want it to match all of them. When I substituteuse 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" +; }, ], ) );
'string( attitude )' => sub { print xvalue; },
as the pod seems to suggest, it no longer prints anything. Am I doing something wrong?
I already have something like this working in XML::Twig, so I can always go back to that.
Thanks!
It should work perfectly the first time! - toma
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: XML::Filter::Dispatcher string rules problem
by barries (Initiate) on Jan 10, 2003 at 14:19 UTC | |
by tye (Sage) on Jan 10, 2003 at 17:14 UTC | |
by toma (Vicar) on Jan 10, 2003 at 21:16 UTC |
Back to
Seekers of Perl Wisdom