in reply to Re^4: Problem in reading parsed xml using XML::Simple
in thread Problem in reading parsed xml using XML::Simple

Try sprinkling lots of "print Dumper" statements to see what you really have in that structure:
print Dumper ( $xst->{cmts}{STBDSG}{dsg} ); print Dumper ( $xst->{cmts}{STBDSG}{dsg}[0] ); print Dumper ( $xst->{cmts}{STBDSG}{dsg}[0]{tag1} );

Replies are listed 'Best First'.
Re^6: Problem in reading parsed xml using XML::Simple
by Perl300 (Friar) on Jun 24, 2015 at 17:57 UTC
    @choroba: I really wish I could put the actual file here but it's quite big and has different data each time as it is generated at runtime. :-( @tangent: I tried your suggestion and it gave following result: I added:
    print Dumper ( $xst->{cmts}{STBDSG}{dsg} ); print Dumper ( $xst->{cmts}{STBDSG}{dsg}[0] ); print Dumper ( $xst->{cmts}{STBDSG}{dsg}[0]{tag1} );
    Which gave:
    $VAR1 = [ {} ]; $VAR1 = {}; $VAR1 = undef;
    So I think problem is what choroba stated earlier that $xst->{cmts}{STBDSG}{dsg}[0]{tag1} is getting undef :-( I think I have to dig deep in this part of my code:
    my $xst; if((not defined $xml) or ($xml =~ m/read\stimeout/i)){ &printXMLErr('request timed out'); } else { my $xs = XML::Simple->new(); $xst = eval { $xs->XMLin($xml,KeyAttr=>1) }; &printXMLErr($@) if($@); }
    It seems that answer to why $xst->{cmts}{STBDSG}{dsg}[0]{tag1} is getting undef is known to either KeyAttr or forcearray (or both). I am trying to find it out from them :-)
      Try working back up the tree one step at a time to see what's happening:
      print Dumper ( $xst->{cmts}{STBDSG} ); then print Dumper ( $xst->{cmts} );
      Can you put some sample files up somewhere else - e.g. Dropbox - I could then have a look.
        Sorry tangent, but I don't have an option for it. The other part of code where fetching data is working as expected is where xml was like:
        <cmts> <name field_name="Name">cts01nsocmo</name> <object field_name="Nemos Object">888</object> <vendor field_name="Vendor">xyz</vendor> </cmts>
        Which was converted as:
        $VAR1 = { 'cmts' => { 'name' => { 'content' => 'cts01nsocmo', 'field_name' => 'Name' }, 'object' => { 'content' => '888', 'field_name' => 'Nemos Object' }, 'vendor' => { 'content' => 'xyz', 'field_name' => 'Vendor' }
        So basically no array and 'content' was there. Where it is not working, xml is like:
        <cmts> <STBDSG> <dsg> <tag1>1</tag1> <tag2>caSystemId</tag2> </dsg> <dsg> <tag1>2</tag1> <tag2>gaSystemId</tag2> </dsg> </STBDSG> </cmts>
        Which was converted as:
        'cmts' => { 'STBDSG' => { 'dsg' => [ { 'tag1' => '1', 'tag2' => 'caSystemId', }, { 'tag1' => '2', 'tag2' => 'gaSystemId', } ] },
        Update: It seems that answer to why $xst->{cmts}{STBDSG}{dsg}[0]{tag1} is getting undef is known to either KeyAttr or forcearray (or both). I am trying to find it out from them :-)