pysome has asked for the wisdom of the Perl Monks concerning the following question:
Dear All,
Now ,i came across a puzzled problem ,pls help me.
my code
the result is :use XML::Simple; use Data::Dumper; my $xml = XML::Simple->new(); my $body = ' <all> <products> <item> <name>a</name> <price>1</price> <count>1</count> </item> <item> <name>b</name> <price>1</price> <count>1</count> </item> </products> </all>'; my $xhash = $xml->XMLin($body); print Dumper($xhash);
$VAR1 = { 'products' => { 'item' => { 'a' => { 'count' => '1', 'price' => '1' }, 'b' => { 'count' => '1', 'price' => '1' } } } };I really don't want to this result. I want to get all "item" info into a Array ref. just like this:
how to carry out the task? Thanks in advance! BTW:i use the option "ForceArray => 1",the result also is not perfect . Pysome$VAR1 = { 'products' => { 'item' =>[ { 'name' => 'a', 'count' => '1', 'price' => '1' }, { 'name' => 'b', 'count' => '1', 'price' => '1' } ] } };
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: A puzzle for parsing XML with XML::Simple!
by bobf (Monsignor) on Jan 25, 2008 at 08:34 UTC | |
by ww (Archbishop) on Jan 25, 2008 at 14:24 UTC | |
by bobf (Monsignor) on Jan 25, 2008 at 15:07 UTC | |
Re: A puzzle for parsing XML with XML::Simple!
by olus (Curate) on Jan 25, 2008 at 11:43 UTC | |
Re: A puzzle for parsing XML with XML::Simple!
by ikegami (Patriarch) on Jan 25, 2008 at 07:51 UTC | |
by pysome (Scribe) on Jan 25, 2008 at 08:34 UTC |
Back to
Seekers of Perl Wisdom