By default, XML::Simple chooses to fold around the following keys by default: name
, key
, id
(see note 1).
Your XML schema contains the id
key, which is why the hash is being split there. You can clear the KeyAttr
value when you create your object (e.g. $xml = XML::Simple( KeyAttr=>"" );
) to override the default behavior.
Your output, with multiple message
entries, would look like:
$VAR1 = {
'message' => [
{
'gsmerror' => '0',
'status' => 'xxxxxx',
'id' => 'msgID',
'donedate' => 'xxxxx',
'sentdate' => 'xxxxx'
},
{
'gsmerror' => '1',
'status' => 'yyyyyy',
'id' => 'msgID2',
'donedate' => 'yyyyy',
'sentdate' => 'yyyyy'
}
]
};
So you need to adjust your code slightly to account for %message
containing an array of message hashes. The format would be the same for a single message
if you keep the ForceArray
option, so your code change would work for both cases.