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

hello friends. i just started using perl and right now i was working on extracting elements from one of the xml file i have. Below the xml dump which is created
$VAR1 = { 'soap' => { 'Response1' => { 'response2' => { 'response3' => [ + { + 'tag1' => 'value1', + 'tag2' => 'value2', + 'tag3' => 'value3', + }, + { + 'tag1' => 'value4', + 'tag2' => 'value5', + 'tag3' => 'value6', + }, + { + 'tag1' => 'value7', + 'tag2' => 'value8', + 'tag3' => 'value9', 'tag4' => '' } + ] }, 'xmlns:ns2' => ' +http://test.com/' } }, 'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/' };

I want to extract "VALUE1" which is associated with the the first tag1. i write the following code, but it does not help. i tried searching for posts. may be i am a new comer and not able to understand this

use XML::Simple; use Data::Dumper; $xml = new XML::Simple(KeyAttr=>('response3'),ForceArray=>('response3' +)); $data = $xml->XMLin("c:\\b.xml") or die $_; print Dumper($data); print"\nStartPrinting First Statement"; print "Data=$data->{'soap'}->{'Response1'}->{'response2'}->{'response3 +'}->[0]->{'tag1'}";

Replies are listed 'Best First'.
Re: Not able to fetch value in a multi-dimentional HASH
by choroba (Cardinal) on Feb 05, 2012 at 20:49 UTC
    With the dump you provided, I'm getting
    Data=value1
    Are you running the same code as posted?
    Is not your output buffered? You might need to append \n to the end of the printed string.

      Hi Choroba - thanks for the reply. yes i am running the same code and used /n. but no data. Also when i do not use keyAttr and other parameters i am getting a different dump(which i understand) and am able to fetch the values. why i dont want this simple dump is because the value1 , value 2 and value 3 are ID values which keeps changing and i have to collect them dynamically. can we collection them, in that case i will have a simpler hash to travel

      Below is the dump when i do not use keyAttr and Force attributes in de +claring the xml variable $VAR1 = { 'response1' => { 'value1' => { 'tag1'=>'value2' 'tag2'=>'value3' 'tag3'=>'value4' }, 'value2' => { 'tag1' => 'value4', 'tag2' => 'value5', 'tag3' => 'value6', } 'value3'=> { 'tag1'=> 'value9' 'tag2'=> 'value10' } };
        /n is not \n. You do not mention value1 as a key in your previous dump, so I am confused. Maybe you can post a part of the XML?