Amazon AWS + SimpleXML
| From: | Brad Fuller | Date: | Mon, 19 Mar 2007 21:30:24 +0000 |
| Subject: | Amazon AWS + SimpleXML | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-250840@lists.php.net to get a copy of this message | ||
Hey guys,
I'm having trouble trying to parse XML results from an Alexa Web information
service from amazon.com, using SimpleXML.
Here is an example response:
<?xml version="1.0"?>
<aws:TrafficHistoryResponse
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>cdfcc49c-5c01-4fc1-87e4-06f2f151e205</aws:RequestId></aws:Oper
ationRequest><aws:TrafficHistoryResult><aws:Alexa>
<aws:TrafficHistory>
<aws:Range>3</aws:Range>
<aws:Site>amazon.com</aws:Site>
<aws:Start>2007-03-15</aws:Start>
<aws:HistoricalData>
<aws:Data>
<aws:Date>2007-03-15</aws:Date>
<aws:PageViews>
<aws:PerMillion>1491</aws:PerMillion>
<aws:PerUser>5.7</aws:PerUser>
</aws:PageViews>
<aws:Rank>30</aws:Rank>
<aws:Reach>
<aws:PerMillion>17359</aws:PerMillion>
</aws:Reach>
</aws:Data>
<aws:Data>
<aws:Date>2007-03-16</aws:Date>
<aws:PageViews>
<aws:PerMillion>1531</aws:PerMillion>
<aws:PerUser>6.0</aws:PerUser>
</aws:PageViews>
<aws:Rank>29</aws:Rank>
<aws:Reach>
<aws:PerMillion>16796</aws:PerMillion>
</aws:Reach>
</aws:Data>
<aws:Data>
<aws:Date>2007-03-17</aws:Date>
<aws:PageViews>
<aws:PerMillion>1411</aws:PerMillion>
<aws:PerUser>5.6</aws:PerUser>
</aws:PageViews>
<aws:Rank>32</aws:Rank>
<aws:Reach>
<aws:PerMillion>16475</aws:PerMillion>
</aws:Reach>
</aws:Data>
</aws:HistoricalData>
</aws:TrafficHistory>
</aws:Alexa></aws:TrafficHistoryResult><aws:ResponseStatus
xmlns:aws="http://alexa.amazonaws.com/doc/2005-10-05/"><aws:StatusCode>Succe
ss</aws:StatusCode></aws:ResponseStatus></aws:Response></aws:TrafficHistoryR
esponse>
$xml = new SimpleXMLElement($result);
var_dump($xml); // produces: object(SimpleXMLElement)#1 (0) {}
I found these posts in the amazon developer forums:
http://developer.amazonwebservices.com/connect/thread.jspa?messageID=55124
http://developer.amazonwebservices.com/connect/thread.jspa?messageID=54000&#
54000
I've tried to register the namespace, but that didn't seem to help...
$xml->registerXPathNamespace( "aws",
"http://alexa.amazonaws.com/doc/2005-10-05/"
);
var_dump($xml->xpath("//aws:Response")); // produces array(0){}
(I tried it with the other url as well, same result)
Any advice is much appreciated.
Thx,
Brad