in reply to Re^2: XML Simple not keeping same structure on xmlout()
in thread XML Simple not keeping same structure on xmlout()

No, it doesn't. First, it worked fine with any change whatsoever. Second, it works with without NoAttr too. It even produces the same tree in both cases.
use strict; use warnings; use Data::Dumper; use XML::Simple; # The fastest existing backend for XML::Simple. local $XML::Simple::PREFERRED_PARSER = 'XML::Parser'; my $xs = XML::Simple->new( NoAttr => $ARGV[0], KeepRoot => 1, NormaliseSpace => 1, ); my $tree = $xs->parse_string( <<'__EOI__' ); <BILLING> <ACCOUNT></ACCOUNT> <RTN></RTN> </BILLING> __EOI__ print( Dumper( $tree ) ); print( $xs->XMLout( $tree ) );
$ perl a.pl 1 $VAR1 = { 'BILLING' => { 'RTN' => {}, 'ACCOUNT' => {} } }; <BILLING> <ACCOUNT></ACCOUNT> <RTN></RTN> </BILLING>
$ perl a.pl 0 $VAR1 = { 'BILLING' => { 'RTN' => {}, 'ACCOUNT' => {} } }; <BILLING> <ACCOUNT></ACCOUNT> <RTN></RTN> </BILLING>

Update: I originally said it produced a different structures.

Replies are listed 'Best First'.
Re^4: XML Simple not keeping same structure on xmlout()
by johnnytc4 (Novice) on Apr 20, 2011 at 18:25 UTC
    Yes on that string it works... Might I add a more specific case where it occurs. Ran the following xml with your code...

    XML

    <BILLING> <ADDTELE1></ADDTELE1> <ADDTELE2></ADDTELE2> <ADDEMAIL></ADDEMAIL> <ADDACCOUNTDETAILS> <ADDACCOUNT> <ACCOUNT></ACCOUNT> <RTN></RTN> </ADDACCOUNT> </ADDACCOUNTDETAILS> </BILLING>

    NoAttr=>0

    $VAR1 = { 'BILLING' => { 'ADDEMAIL' => {}, 'ADDTELE2' => {}, 'ADDACCOUNTDETAILS' => { 'ADDACCOUNT' => { 'RTN' => + {}, 'ACCOUNT +' => {} } }, 'ADDTELE1' => {} } }; <BILLING> <ADDACCOUNTDETAILS name="ADDACCOUNT"> <ACCOUNT></ACCOUNT> <RTN></RTN> </ADDACCOUNTDETAILS> <ADDEMAIL></ADDEMAIL> <ADDTELE1></ADDTELE1> <ADDTELE2></ADDTELE2> </BILLING>

    NoAttr=>1

    $VAR1 = { 'BILLING' => { 'ADDEMAIL' => {}, 'ADDTELE2' => {}, 'ADDACCOUNTDETAILS' => { 'ADDACCOUNT' => { 'RTN' => + {}, 'ACCOUNT +' => {} } }, 'ADDTELE1' => {} } }; <BILLING> <ADDACCOUNTDETAILS> <name>ADDACCOUNT</name> <ACCOUNT></ACCOUNT> <RTN></RTN> </ADDACCOUNTDETAILS> <ADDEMAIL></ADDEMAIL> <ADDTELE1></ADDTELE1> <ADDTELE2></ADDTELE2> </BILLING>
      ForceArray => 1 will help in that situation, but will produce a much more elaborate structure. But really, XML::Simple is not designed to be idempotent.
Re^4: XML Simple not keeping same structure on xmlout()
by johnnytc4 (Novice) on Apr 21, 2011 at 15:17 UTC
    You are right, ForceArray=>1 works. It keeps everything in format, except the order which shouldn't matter in my case.

    The only issue I am having now is parsing through the tree. I am trying to write a recursive function to walk through this hash of array/hashes, which is proving to be difficult.