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

So don't use NoAttr. If you're lucky, you might get the same structure back. Better yet, don't use XML::Simple. Upd: I use XML::LibXML.
  • Comment on Re: XML Simple not keeping same structure on xmlout()

Replies are listed 'Best First'.
Re^2: XML Simple not keeping same structure on xmlout()
by mikeraz (Friar) on Apr 20, 2011 at 16:15 UTC

    Better yet, don't use XML::Simple.

    And your XML::<Suggested Module/> is ___ ?
    It's a tough forest to thin.


    Be Appropriate && Follow Your Curiosity
Re^2: XML Simple not keeping same structure on xmlout()
by johnnytc4 (Novice) on Apr 20, 2011 at 17:07 UTC
    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
      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>
        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.