I am trying to get the number of children of the root element and my script
gives me the number of children of the children instead.

Here is my XML document (ejournlist.xml):

<?xml version='1.0'?>
<EJOURNLIST>
  <EJOURN>
      <TI>Africa Confidential</TI>
      <ISSUE>Vol. 1, no.1</ISSUE>
      <FILEFORMAT>PDFformat</FILEFORMAT>
  </EJOURN>
  <EJOURN>
      <TI>Time Magazine</TI>
      <ISSUE>Vol. 1, no.1</ISSUE>
      <FILEFORMAT>TXTformat</FILEFORMAT>
  </EJOURN>
</EJOURNLIST>



Here is my perl script:

#!/usr/bin/perl -w
use XML::Simple;
#create object
my $xml = new XML::Simple;

#read XML file
my $data = $xml->XMLin("ejournlist.xml");

my $ejourn_cnt = scalar(keys %{$data->{'EJOURN'}});
print "The number of EJOURNs is: $ejourn_cnt \n";

*The scripts returns 3 when it should return 2.*

Any advice would be appreciated.

DA

**

Reply via email to