Not an ARRAY reference. Problems reading a simple XML file



My script is having problems reading and XML file with only one record in
it. When I add two or more records, there are no problems. The error is
"Not and ARRAY reference.."

Here is the PROBLEM xml file (test.xml):

<?xml version="1.0" encoding="ISO-8859-1" ?>
<DATA>
<RECORD>
<COLLNAME>FBIS2004</COLLNAME>
<DOCI>CP1</DOCI>
</RECORD>
</DATA>


Here is the WORKING xml file:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<DATA>
<RECORD>
<COLLNAME>FBIS2004</COLLNAME>
<DOCI>CP1</DOCI>
</RECORD>
<RECORD>
<COLLNAME>FBIS2005</COLLNAME>
<DOCI>CP2</DOCI>
</RECORD>
</DATA>

Here is my script:

#!/usr/bin/perl
use XML::Simple;
use Data::Dumper;

$xml = new XML::Simple (KeyAttr=>[]);
$data = $xml->XMLin("test.xml");
#print Dumper($data);
print "There are " . scalar(@{$data->{RECORD}}) . " records.\n";
foreach my $var (@{$data->{RECORD}})
{
print $var->{DOCI} . "\n";
print $var->{COLLNAME} . "\n";
}

Does anyone have an explaination for this?

Thanks in advance,
DA


Relevant Pages

  • Re: using xml to save/open project data
    ... http://www.TransProCalc.org - Free translation project mgmt software ... set filename tk_getOpenfile ... Exec'ing the script you run it as a separate process, your script won't be able to access its vars. ... generating the xml file is easy enough. ...
    (comp.lang.tcl)
  • using xml to save/open project data
    ... Now, I've made a program, a translation project management tool, ... set filename tk_getOpenfile ... to run the script to reset the variables to reopen the project. ... I've been told that generating an xml file is the best way to go about ...
    (comp.lang.tcl)
  • RE: Problem with LWP::UserAgent
    ... have an xml file that contains a list of URLs. ... hash and pass them as a parameter into the function that does LWP get. ... > assume your script is named net.pl, you can involve the debugger with: ...
    (perl.beginners)
  • Re: WSH and XML Parser
    ... Once you pass that hurdle it is routine selectNodes or selectSingleNode. ... an xml file there is a fat chance that you will never learn how to read one. ... For those who manage to set their server shares via script, ... > I would like to map a set of network drives in which the data fro the ...
    (microsoft.public.scripting.wsh)
  • Re: The wonderful non-intuitive php include statement
    ... The database configuration is an XML file. ... relative paths are relative to the executing script, ...
    (comp.lang.php)