Problems with XML and Perl. Have a look at xmllint on Mac and I'd assume linux...
Think of XML as having two types of data... "Data" and "Meta Data", everything between matched ">ME ME ME<" is real data, everything between matched <"me" "me" "me"> is meta data. Mixing them up means you get errors ie xmllint showed me this
data.xml:2: parser error : error parsing attribute name
<employee="risc_31">
^
data.xml:2: parser error : attributes construct error
<employee="risc_31">
^
data.xml:2: parser error : Couldn't find end of Start Tag employee line 2
<employee="risc_31">
^
data.xml:2: parser error : Extra content at the end of the document
<employee="risc_31">
^
Change your XML to look something more like. Note I've added a "wtf" entry to this record ie I've made the "risc_nn" data as a real part of the employee record, not meta data...
<?xml version="1.0"?>
<foo>
<employee>
<wtf>risc_31</wtf>
<name>John Doe</name>
<age>43</age>
<sex>M</sex>
<department>Analyst</department>
</employee>
<employee>
<wtf>risc_32</wtf>
<name>Pradeep</name>
<age>23</age>
<sex>M</sex>
<department>HR</department>
</employee>
</foo>
The following Perl program will now work
use strict;
use warnings;
use XML::Simple;
use Data::Dumper;
my @xml=new XML::Simple;
my $data=XMLin("data.xml");
print Dumper($data);
and provide the following result...
$VAR1 = {
'employee' => {
'John Doe' => {
'wtf' => 'risc_31',
'sex' => 'M',
'department' => 'Analyst',
'age' => '43'
},
'Pradeep' => {
'age' => '23',
'wtf' => 'risc_32',
'sex' => 'M',
'department' => 'HR'
}
}
};
If you want to loop over that it's a hash reference so use the following...
for my $key (%{$data}) {
print $data->{$key} . "\n";
}
Or any myriad ways to do anything in Perl.