I have XML data that will be like this
<Root>
<Bag Identifier="1">
<Code Amount="0" Code="XA" Conversion="0" Currency="INR" Desc="" Id="1"/>
</Bag>
<Bag Identifier="2">
<Code Amount="21" Code="XA" Conversion="0" Currency="INR" Desc="" Id="2"/>
</Bag>
</Root>
I want to parse this and create a Perl hash as below. The Identifier attribute of each Bag element should be the primary hash key.
'2' => {
'Amount' => "21",
'Code' => "XA",
'Currency' => "INR",
}
'1' => {
'Amount' => "0",
'Code' => "XA",
'Currency' => "INR",
}
This is my Perl code
my $parser = XML::LibXML->new();
my $xml_doc = $parser->parse_string($response);
my $test_node = $xml_doc->findnodes('//Bag/');
print Dumper($test_node);
print $test_node->find('@Id')->string_value();
How can I create the hash that I have described?