views:

224

answers:

1

Hi,

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?

TIA,
Benjy

+3  A: 

You can get the attributes of an XML element by calling the attributes() function on an XML node. You can then var_dump the return value of the function.

More info at php.net http://php.net/manual/en/simplexmlelement.attributes.php

Example code from that page:

$xml = simplexml_load_string($string);
foreach($xml->foo[0]->attributes() as $a => $b) {
    echo $a,'="',$b,"\"\n";
}
Niels Bom
Thanks. That'd be it.
benjy