Given the below XML and script, I can produce this:
{
Item => {
Details => { color => { Val => "green" }, texture => { Val => "smooth" } },
},
}
but, I really want the following:
{
Item => {
Details => { color => "green", texture => "smooth" },
},
}
I can't use GroupTags here because there could be many Details items (Key/Val pairs), and they could be unknown before processing. Is it possible to produce the desired structure without resorting to manual extraction via XPath, SAX, etc.?
use strict;
use warnings;
use Data::Dump;
use XML::Simple;
my $xml = do { local $/; scalar <DATA> };
my $obj = XMLin(
$xml,
NoAttr => 1,
GroupTags => { Details => 'Item' },
KeyAttr => [ 'Key'],
);
dd($obj);
exit;
__END__
<?xml version="1.0" encoding="UTF-8"?>
<List attr="ignore">
<Item attr="ignore">
<Details attr="ignore">
<Item attr="ignore">
<Key>color</Key>
<Val>green</Val>
</Item>
<Item attr="ignore">
<Key>texture</Key>
<Val>smooth</Val>
</Item>
</Details>
</Item>
</List>