Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I have been scratching my head trying to figure out what is wrong with my parsing rules and I find put in some print statements in the rules and found that XML::Rules is parsing the XML "inside out". I am reading through the XML top to bottom to develop my rules and logic and find I am missing some info. Now I see why.

take the following example:

<?xml version="1.0"?><xmltest xmlns="http://localhost/nothing"> <summary> <item> <value>1.0</value> </item> </summary> <detail1> <item> <value>2.0</value> </item> </detail1> <detail2> <item> <value>3.0</value> </item> </detail2> </xmltest>
I have been attacking this (seemingly) incorrectly with rules like the following:
my @rules_lpo = ( default => sub { $_[0] => $_[1]->{_content}; print "$_[0] : $_[1]->{_content}\n"; }, 'summary' => sub { $insummary = 1; }, 'detail1' => sub { $ind1 = 1; $insummary = 0; }, 'detail2' => sub { $ind2 = 1; $ind1 = 0; }, 'item' => sub { if ($insummary) { $sumvalue = $_[1]->{value}; } if ($ind1) { $d1value = $_[1]->{value}; } if ($ind2) { $d2value = $_[1]->{value}; } } );

This does not work. value is processed before item which is processed before the outside tag so the flags get set AFTER the section has already processed the guts. I only saw this from the print statement in '_default' rule which I added out of sheer frustration.

The result is $sumvalue is equal to d1 value, $d1value = d2 value and $d2value is never set. I have been losing my mind over this.

How do I properly handle duplicate tags in different sections if I cannot flag them due to the way the XMl is processed in this inside out manner???

Update: Updated the XML to have proper wrapper.


In reply to XML::Rules parsing inside out? by bfdi533

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-19 02:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found