in reply to Problem in reading parsed xml using XML::Simple

...nothing is printed ...
That might an indication that the top level $dsg_tags is undef .. you don't show us which variable you dumped.

        "Despite my privileged upbringing, I'm actually quite well-balanced. I have a chip on both shoulders."         - John Nash

  • Comment on Re: Problem in reading parsed xml using XML::Simple

Replies are listed 'Best First'.
Re^2: Problem in reading parsed xml using XML::Simple
by Perl300 (Friar) on Jun 24, 2015 at 14:59 UTC
    @choroba: Yes, when I tried like that even I am getting the correct output as you showed. But actually I am dumping from $xml where I have the actual xml file using following lines. My apologies for not being clear about this before. Also in other parts of code I am able to fetch data by referencing $xst

    @NetWallah: I am using this for dumping the xml

    my $xs = XML::Simple->new(); $xst = eval { $xs->XMLin($xml,KeyAttr=>1) }; &printXMLErr($@) if($@); print "Value of \$xst is:\n"; print Dumper($xst);
    Here print Dumper($xst); shows all the data from xml converted into the format I provided. And I am able to fetch data using reference to these like: $xst->{cmts}->{Pre_EQ}->{groupDelayMag}->{content}; I think the problem I am having is about the elements that are in [] (array of hash?) displayed in $xst
      Try specifying the index of the array element in square brackets:
      print $xml->{cmts}{STBDSG}{dsg}[0]{tag1};
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
        Tried using something like
        my %dsg_tags; $dsg_tags{'tag1'} = $xst->{cmts}{STBDSG}{dsg}[0]{tag1}; foreach (sort keys %dsg_tags) { print "$_ : $dsg_tags{$_}\n"; }
        And still getting blank value for tag1 even though there actually is a value. There is a warning as well like:
        Use of uninitialized value in concatenation (.) or string at ./<script +_name>.pl line <>. tag1 :