I've got a simple xml document ...
<?xml version="1.0" encoding="UTF-8" ?>
<charge-type-control>
<charge code="FRT" name="frtamt"/>
<charge code="SV1" name="savamt"/>
<charge code="SV2" name="savamt"/>
<charge code="SV3" name="savamt"/>
<charge code="SV4" name="savamt"/>
<charge code="SV5" name="savamt"/>
</charge-type-control>
that I would like to parse into the data structure ...
{
'SV1' => 'savamt',
'SV5' => 'savamt',
'SV2' => 'savamt',
'FRT' => 'frtamt',
'SV3' => 'savamt',
'SV4' => 'savamt'
};
However, the closest I've been able to get with XML::Simple is ...
{
'charge' => {
'SV1' => {
'name' => 'savamt'
},
'SV5' => {
'name' => 'savamt'
},
'SV2' => {
'name' => 'savamt'
},
'SV4' => {
'name' => 'savamt'
},
'SV3' => {
'name' => 'savamt'
},
'FRT' => {
'name' => 'frtamt'
}
}
};
using this XMLin line ...
$ref = XMLin('charge-type-control.xml', KeyAttr => ['code']);
the docs allude to using ValueAttr like...
$ref = XMLin('charge-type-control.xml', KeyAttr => ['code'], ValueAttr
+ => ['name']);
but the results are the same. So either it doesn't do what I think it does or what I want to do is impossible.
Can I coerce XML::Simple to do exactly what I want or do I have to write my own transformer like...
my %myref;
for my $key (keys %{$ref->{charge}}) {
$myref{$key} = $ref->{charge}->{$key}->{name};
}
to get exactly what I want?