Peeps, I'm a bit stumped by a piece of code that doesn't behave like I think it should. I'm simply trying to parse an XML document with XML::Simple and reference one of the fields. The code is:-
# parse the message (executed within eval so parsing errors are no +n-fatal) eval { $parsed_xml = XMLin( $message, forcearray => 1, keyattr => [] ); }; # if parsing errors were encountered, write the appropriate messag +e to the log if ($@) { &stop_it($ERROR, $XMLERROR, "Parsing error encountered - $@", +$log_file); } $queue_name = $parsed_xml->{descriptor}->{inputQueue}; &log_it($INFO, "inputQueue is $queue_name", $log_file); print Dumper($parsed_xml);
When I check the log, $queue_name is blank. When I view the Data::Dumper output I see:-
'descriptor' => [ { 'uniqueId' => [ 'X\'414d51204d534f4c5530 +3220202020203ed6d4ec00023332\'' ], 'resubCounter' => [ '0' ], 'failureTimestamp' => [ '2004-01-13 15:0 +0:00.000' ], 'errorCode' => [ '1234' ], 'messageType' => [ 'TEST.MESSAGE' ], 'inputQueue' => [ 'BLACKHOLE' ], 'destinationSystem' => [ 'NOWHERE' ], 'dataFormat' => [ 'XML' ], 'portfolioCode' => [ 'NONE' ], 'errorDescription' => [ 'Blackhole messa +ge' ], 'sourceSystem' => [ 'TEST' ] } ], 'body' => [ { 'contents' => [ 'Some data' ] } ]
So, it looks to me like the field descriptor/inputQueue is present but not being picked up by the code. I've had code like this working in the past but for the life of me I can't spot what I'm doing wrong. Can you? Thanks, J.

In reply to XML parsing problem. by jgooch

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.