rhxk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, My objective is to read a xml file and extract data off of it as both the elements and attributes...well here, let me start by some codes.
<site-catalog> <site> <name>abc</name> <header> <date id = "1992-06-17T00:00:00"> <fullname>AybBemGim</fullname> <a>101 </b> <b>UNKN</b> ... <operator>Zarzand</operator> <agency>NONE</agency> <run-by>Pepo</run-by> <observables>UNKN</observables> </date> <date id = "1992-06-26T00:00:00"> <fullname>AybBemGim</fullname> <b>101</b> <l>+342809.83</l> .... </date> </header> </site> </site-catalog>
I want to load these to a hash array so I can sort by the date id and extract the data inside that date id. my perl is as such:
#!/usr/bin/perl use XML::Simple; use Data::Dumper; $xmlfile = "/home/rob/xml/config.xml"; #create object $xml = new XML::Simple; #read XML file $hash = $xml->XMLin($xmlfile); %element = $hash->{site}->{header}->{date}; foreach $key (sort keys %element) { print $key; } #print Dumper $hash;
How can I read the date id and the elements inside this tree?
(I have a feeling the answer is staring right in front of me but I haven't figured it out yet)
Can you guys give me some hints/ideas?
..thanx..

Replies are listed 'Best First'.
Re: XML::Parser help
by rhxk (Beadle) on Feb 02, 2006 at 22:06 UTC
    I knew it...it was staring at me the whole time...
    just had to change the
    foreach $key (sort keys %element) {
    to
    foreach $key (sort keys %{$element}) {
    ...well, thanx anywayz... --Rob