Getting number of children of the root in an XML object
- From: davidlamontadams@xxxxxxxxx (Dave Adams)
- Date: Fri, 31 Mar 2006 15:42:56 -0500
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
**
- Prev by Date: Re: How to printout matching pattern in command line
- Next by Date: Script need help
- Previous by thread: How to printout matching pattern in command line
- Next by thread: Script need help
- Index(es):
Relevant Pages
|