Question
Here's an example of my xml data
<GetSendStatisticsResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/">
<GetSendStatisticsResult>
<SendDataPoints>
<member>
<DeliveryAttempts>69</DeliveryAttempts>
<Timestamp>2011-09-12T01:00:00Z</Timestamp>
<Rejects>0</Rejects>
<Bounces>0</Bounces>
<Complaints>0</Complaints>
</member>
<member>
<DeliveryAttempts>1</DeliveryAttempts>
<Timestamp>2011-09-08T17:00:00Z</Timestamp>
<Rejects>0</Rejects>
<Bounces>0</Bounces>
<Complaints>0</Complaints>
</member>
<member>
<DeliveryAttempts>282</DeliveryAttempts>
<Timestamp>2011-09-09T18:00:00Z</Timestamp>
<Rejects>0</Rejects>
<Bounces>0</Bounces>
<Complaints>0</Complaints>
</member>
And here's my code:
$xml = simplexml_load_string($resp);
$result = $xml->xpath('//member');
foreach($result->member as $member)
{
echo "<p>";
echo "Delivery Attempts: ".$member->DeliveryAttempts."<br/>";
echo "</p>";
}
But it's failing to work. I'm also OK if $xml is converted into JSON or an Array. Whatever works best to iterate through the xml to display DeliveryAttempts.
Solution
This is due to the XML namespace. Do something like this:
$xml->registerXPathNamespace( 'ses', 'http://ses.amazonaws.com/doc/2010-12-01/' );
$result = $x->xpath( '//ses:member' ) ;
OTHER TIPS
Try
foreach ($result as $member) {
...
}
instead.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow