isync has asked for the wisdom of the Perl Monks concerning the following question:

Hi there! I am trying to writing a List of Hashes out as XML via XML:Simple. Ok. But when I try to read it in again, it fails! Repeated child elements do not give a list of hashes... Checking the data-structure via Data::Dumper shows everything is fine:
$VAR1 = { 'node' => [ { 'key1' => 'value1', 'key2' => 'value2', }, { 'key1' => 'value3', 'key2' => 'value4', }, ], };
XML:Simple::XMLout with option "noattr => 1" renders:
<root> <node> <key1>value1</key1> <key2>value2</key2> </node> <node> <key1>value3</key1> <key2>value4</key2> </node> </root>
BUT: When I do XML:Simple::XMLin with option "suppressempty => undef" Data:Dumper shows this:
$VAR1 = { 'node' => { 'value1' => { 'key2' => 'value2', }, 'value3' => { 'key4' => 'value4', }, }, };
WHY? And how can I get XML:Simple to properly slurp back in my LoH data-structure??

Replies are listed 'Best First'.
Re: XML::Simple - repeated child elements does not give list of hashes
by davorg (Chancellor) on Mar 23, 2007 at 14:07 UTC
      You are right, and I already tried it:
      "forcearray => 1" does an unwanted "all"
      "forcearray => [ 'node' ]" does nothing, just ignored - can somebody explain to me why? Is my data structure wrong?? As test:
      "forcearray => [ 'key1' ]" works and outputs "key1" as a one-item array...

      I am running XML::Simple v2.03 (can't upgrade)
        Most things in perl are case sensitive. So: use 'ForceArray', not 'forcearray'.