Hello,
I am trying to parse date from the alexa.com api, although to simplify things I have currently saved the xml file to my server.
This is my xml, which I have also validated:
<?xml version="1.0"?>
<aws:UrlInfoResponse xmlns:aws="http://alexa.amazonaws.com/doc/2005-10-05/"><aws:Response xmlns:aws="http://awis.amazonaws.com/doc/2005-07-11"><aws:OperationRequest><aws:RequestId>xxxxxxxxxxxxxxxx</aws:RequestId></aws:OperationRequest><aws:UrlInfoResult><aws:Alexa>
<aws:TrafficData>
<aws:DataUrl type="canonical">phpbuilder.com/</aws:DataUrl>
<aws:Rank>14781</aws:Rank>
</aws:TrafficData>
</aws:Alexa></aws:UrlInfoResult><aws:ResponseStatus xmlns:aws="http://alexa.amazonaws.com/doc/2005-10-05/"><aws:StatusCode>Success</aws:StatusCode></aws:ResponseStatus></aws:Response></aws:UrlInfoResponse>
Now my code:
$xml = simplexml_load_file('alexa.xml');
if (file_exists('alexa.xml')) {
$xml = simplexml_load_file('alexa.xml');
var_dump($xml); // Gives object(SimpleXMLElement)#2 (0) { }
} else {
exit('Error.');
}
There is no error, and the xml should be valid... but how do I access the traffic rank which in this case is 14781?
Something like this?
echo $xml->{'aws:TrafficData[0]'}->{'aws:Rank'}; ?
or
echo $xml->{'aws:Response'}->{'aws:TrafficData[0]'}->{'aws:Rank'};
This is driving me crazy, any help much appreciated!
Cheers,
hal