mifflin has asked for the wisdom of the Perl Monks concerning the following question:
I've got a simple xml document ...
that I would like to parse into the data structure ...<?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>
However, the closest I've been able to get with XML::Simple is ...{ 'SV1' => 'savamt', 'SV5' => 'savamt', 'SV2' => 'savamt', 'FRT' => 'frtamt', 'SV3' => 'savamt', 'SV4' => 'savamt' };
using this XMLin line ...{ 'charge' => { 'SV1' => { 'name' => 'savamt' }, 'SV5' => { 'name' => 'savamt' }, 'SV2' => { 'name' => 'savamt' }, 'SV4' => { 'name' => 'savamt' }, 'SV3' => { 'name' => 'savamt' }, 'FRT' => { 'name' => 'frtamt' } } };
the docs allude to using ValueAttr like...$ref = XMLin('charge-type-control.xml', KeyAttr => ['code']);
$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...
to get exactly what I want?my %myref; for my $key (keys %{$ref->{charge}}) { $myref{$key} = $ref->{charge}->{$key}->{name}; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: XML::Simple help
by saintmike (Vicar) on Mar 08, 2005 at 00:47 UTC | |
by holli (Abbot) on Mar 08, 2005 at 06:01 UTC | |
Re: XML::Simple help
by graff (Chancellor) on Mar 08, 2005 at 03:38 UTC | |
Re: XML::Simple help
by murugu (Curate) on Mar 08, 2005 at 06:23 UTC | |
by mirod (Canon) on Mar 08, 2005 at 07:16 UTC |
Back to
Seekers of Perl Wisdom