Hi, I'm learning perl and web application now. I have a xml data as shown below.
<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
<photos page="1" pages="102" perpage="2" total="508">
<photo id="1969474222" owner="20137329@N04" secret="8ebd15f901" server="2185" farm="3" title="allen-iverson-dunks" ispublic="1" isfriend="0" isfamily="0" />
<photo id="1952424144" owner="7974492@N03" secret="a18966828b" server="2241" farm="3" title="Celtics vs. Nuggets" ispublic="1" isfriend="0" isfamily="0" />
</photos>
</rsp>
Then I used XML:: Simple to analyze it.
#!/usr/bin/perl
use XML:: Simple;
use Data:: Dumper;
open(IN, "api.flickr.com.xml");
$xml = join("", <IN>);
close(IN);
$parser = new XML:: Simple(ForceArray => 1);
$xml_ref = $parser->XMLin($xml);
print Dumper($xml_ref);
The result is shown below.
$VAR1 = {
'photos' => [
{
'page' => '1',
'photo' => {
'1950975040' => {
'owner' => '88092548@N00',
'isfriend' => '0',
'ispublic' => '1',
'secret' => '6d25ddd8c4',
'farm' => '3',
'server' => '2047',
'title' => 'Allen Iverson',
'isfamily' => '0'
},
'1951626474' => {
'owner' => '8723641@N06',
'isfriend' => '0',
'ispublic' => '1',
'secret' => '72908e1302',
'farm' => '3',
'server' => '2318',
'title' => 'Ich und allen Iverson ...',
'isfamily' => '0'
}
},
'total' => '508',
'pages' => '102',
'perpage' => '2'
}
],
'stat' => 'ok'
};
I want to know how to access the value of each attribute(id, owner, etc). Usually, I had simple data, then I refered each value by for exp.
$xml_ref->{Results}->[0]->{photos}->[1]->{id}->[0];
But with data format I'm having now, I can't access the value of each attribute.