Accessing @attribute from SimpleXML

benjy picture benjy · Oct 30, 2009 · Viewed 139.8k times · Source

I am having a problem accessing the @attribute section of my SimpleXML object. When I var_dump the entire object, I get the correct output, and when I var_dump the rest of the object (the nested tags), I get the correct output, but when I follow the docs and var_dump $xml->OFFICE->{'@attributes'}, I get an empty object, despite the fact that the first var_dump clearly shows that there are attributes to output.

Anyone know what I am doing wrong here/how I can make this work?

Answer

zysoft picture zysoft · Sep 26, 2012

Try this

$xml->attributes()->Token