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

I am new to xml parsing and for the most part XML simple is able to read in my XML file just fine. However in the case that the child tags have empty values, XMLout will replace the child tag name with "name" and use the original tag as the new value. *THIS ONLY HAPPENS IF ALL CHILD TAGS WITHIN A PARENT HAVE NO VALUES*

Now I am not sure if it is my config flags that are wrong or if there is something else I am missing. Any pointers would be very much appreciated! Thanks!
my $xs1 = XML::Simple->new(NoAttr=>1,KeepRoot=>1,NormaliseSpace=>1 ); my $xml_data = $xs1->parse_file($xml_path); #print Dumper($xml_data);

Example Original XML

<BILLING> <ACCOUNT></ACCOUNT> <RTN></RTN> </BILLING>

Example Outputed XML

<BILLING> <name>ACCOUNT</name> <name>RTN</name> </BILLING>

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

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