Tuesday, June 30, 2009

Access SimpleXMLElement Object Attributes

PHP simplexml_load_string is a simple way to extract xml data into an object. If you have the following result from calling

$obj = simplexml_load_string($xml);


SimpleXMLElement Object
(
[@attributes] => Array
(
[status] => success
)

[auth] => SimpleXMLElement Object
(
[token] => dxoYGmwncmntH07jJGro5h0rxNfE2Ni6
[seq] => 33
)

)


you can access status by

$obj->attributes()->status