Not an ARRAY reference when using Perl's XML::Simple -
Not an ARRAY reference when using Perl's XML::Simple -
i getting xml::simple , have had problem xml::simple module choking when parsing 1 record. perl code below.....
#!/usr/bin/perl # utilize module utilize warnings; utilize strict; utilize xml::simple; utilize data::dumper; # create object $xml = new xml::simple; # read xml file $data = $xml->xmlin("owners.xml"); foreach $e (@{$data->{owner}}) { print $e->{ownerid}->{ownercik}."\n"; print $e->{ownerid}->{ownername}."\n"; print "\n"; }
when utilize xml, works beautifully...
<?xml version="1.0"?> <ownershipdocument> <owner> <ownerid> <ownercik>0001234878</ownercik> <ownername>public john q</ownername> </ownerid> </owner> <owner> <ownerid> <ownercik>0001234877</ownercik> <ownername>public jane q</ownername> </ownerid> </owner> </ownershipdocument>
it's when have 1 record have issues... xml below example...
<?xml version="1.0"?> <ownershipdocument> <owner> <ownerid> <ownercik>0001234878</ownercik> <ownername>public john q</ownername> </ownerid> </owner> </ownershipdocument>
the error when parsing is.....
not array reference @ ./so_parse.pl line 14.
i thought solution utilize forcearray , changed include forcearray..
my $data = $xml->xmlin("so_single.xml", forcearray=>1);
now ......
not hash reference @ ./so_parse.pl line 16.
admittedly, i'm little hazy on complex info structures i'm trying solve how parse these owners when have one.
any help great! janie
try this:
my $data = $xml->xmlin("so_single.xml", forcearray=>['owner']);
it should force array on 'owner' elements.
xml perl parsing
Comments
Post a Comment