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

It now puts the tags in this format now :

<BILLING name="ADDACCOUNTDETAILS"> <ADDACCOUNTDETAILS name="RTN" /> <ADDACCOUNTDETAILS name="ACCOUNT" /> </BILLING>
I guess I'll have to try XML:xlib

Replies are listed 'Best First'.
Re^3: XML Simple not keeping same structure on xmlout()
by ikegami (Patriarch) on Apr 20, 2011 at 17:50 UTC
    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.

      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.
      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.