FlanOSU has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing deep XML
by lostjimmy (Chaplain) on Feb 24, 2010 at 22:39 UTC | |
|
Re: Parsing deep XML
by grantm (Parson) on Feb 25, 2010 at 03:22 UTC |