I have successfully run the basic XML parsing examples found around the internet, but when I try to apply it to my actual xml files, I am stumped.

I could use some assistance in learning how to access the lower levels of this XML tree. Here is some of the output from Dumper (hopefully this is legible):

$VAR1 = { 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'ICD_Name' => 'MFU_icd', 'ICD_Description' => { 'MsgData' => { 'MsgDataRegion' => { 'Msg_Da +ta' => { + 'Array' => { + 'ArrayName' => 'MFU_ID', + 'NumOfArrayRepetitions' => '1', + 'StructureType' => [ + { + 'DataLine' => {

I am trying to read down to the DataLine level, but I can't even get it to output the top level. Here is my code:

#!/usr/bin/perl # use module use strict; use XML::Simple; use Data::Dumper; # read XML file my $xmlfile = "./GA_MFU_Get_Status.xml"; my $ref = eval { XMLin($xmlfile) }; # print entire output print Dumper($ref); foreach my $item (@{$ref->{ICD_Description}}) { print $item->{MsgData}, "\n"; print ": ", $item->{MsgData}->{MsgDataRegion}->{Msg_Data}->{Array} +, "\n"; print ": ", $item->{MsgData}->{MsgDataRegion}->{Msg_Data}->{Array} +->{StructureType}->{DataLine}, "\n"; print ": ", $item->{MsgData}->{MsgDataRegion}->{Msg_Data}->{Array} +->{StructureType}->{DataLine}->{DataField}, "\n"; print "\n"; }

I get the message "Not an ARRAY reference at C:\GA_MFU_ICD_XML\XML\XMLparser.pl line 18." Anything to get my on the right track would be much appreciated.


In reply to Parsing deep XML by FlanOSU

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.