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.
In reply to Re: XML::Simple - Make arrays out of class attribute
by ikegami
in thread XML::Simple - Make arrays out of class attribute
by mscharrer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |