Hi again.
I have taken XML::Rules for a ride, and it is really nice. It also looks very fast. All in all, a great tool.
But it did take me a while to get the inner logic of how it works, despite your evident efforts at writing the documentation. It is in the end excellent as a reference, but as far as I am concerned it lacked a bit in terms of being a tutorial, although I understand that the matter is complex and not easy to explain simply.
What was not evident, is how one deals with a frequent case where a given <tag> can be a subtag of different parent tags, and needs to be interpreted differently depending on that, like <average-color> below :
<fruits> <average-color>purple</average-color> <fruit type="banana"> <average-color>yellow</average-color> </fruit> <fruit type="apple"> <average-color>greenish</average-color> </fruit> </fruits>

I could never get the "somewhat x-path-like" tags to work, so I resorted to :
'average-color' => sub { if ($_[2]->[-1] eq 'fruit') { # parent tag is <fruit> return 'fruit-average-color' => $_[1]->{_content}; } elsif ($_[2]->[-1] eq 'fruits') { # parent tag is <fruits> return 'global-average-color' => $_[1]->{_content}; } else { # anything else, discard return undef; } },

Another aspect a bit mysterious is how exactly the following construct actually works :
'tag' => sub { return '@'.$_[0] => $_[1]->{_content}; },

I mean, I know it works and returns the contents of <tag>s as an array, but the way in which it does that is a bit mysterious, even after looking at the module code (I must admit that a lot remains mysterious to me, after looking at the code though).

All in all, thanks for the tip, and thanks for the module. I will re-use it.

In reply to Re^5: Apache +XML parsing by soliplaya
in thread Apache +XML parsing by soliplaya

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.