in reply to XML::Simple - Make arrays out of class attribute
XML is a parser. It returns what is. If you want to perform transformations, you'll have to do them yourself.
use Data::Dumper; my $parent = { div => [ { class => 'A', content => '1' }, { class => 'A', content => '2' }, { class => 'A', content => '3' }, { class => 'B', content => '4' }, { class => 'B', content => '5' }, { class => 'B', content => '6' }, ], }; my $grouped = {}; for ( @{ $parent->{div} } ) { my $class = delete $_->{class}; push @{ $grouped->{$class} }, $_; } $parent->{div} = $grouped; print(Dumper($parent));
By the way, the need to perform such transformations could indicate that your XML's schema incorrectly represents your data.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: XML::Simple - Make arrays out of class attribute
by juster (Friar) on Sep 14, 2008 at 22:07 UTC | |
by ikegami (Patriarch) on Sep 14, 2008 at 22:13 UTC | |
|
Re^2: XML::Simple - Make arrays out of class attribute
by mscharrer (Hermit) on Sep 14, 2008 at 20:10 UTC |