I have a clients server returning the following (strange) XML response; how do I access each key:value pair?
$xml = '<?xml version="1.0"?>
<response>
<string key="__status">success</string>
<string key="id">1000</string>
<string key="mask">9999</string>
</response>';
I was hoping that the following would work, but it appears not.
$test = new SimpleXMLElement($xml);
echo "Mask: " . $xml->response->mask; // Mask: 9999
If you want a specific element, you can use XPath:
(this requires PHP 5.2)
This would give you:
If you want all elements, you have to iterate over all
stringelements and access their text andkeyattribute:gives: