In the pod for XML::Filter::Dispatcher is says:
## Print the text of all <description> elements 'string( description )' => sub { print xvalue },
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.

Here is my full example, which is a slightly modified example from the pod:

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" +; }, ], ) );
This prints the contents of only one <attitude> tag, and I want it to match all of them. When I substitute
'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


In reply to XML::Filter::Dispatcher string rules problem by toma

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.