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

5 comments:

Unknown said...

Like this

Arif said...

Like this

Anonymous said...

Thanks, you just made my day after spending a few hours on approaches that went nowhere.

Anonymous said...

thanks, you saved my time!

Anonymous said...

Thanks! You saved my time searching solutions for this.