I'm reading a feed into a variable using SimpleXML and get the below output using dprint_r. I'm having trouble referencing the array elements, so I think I don't understand the structure here - is it a proper array or just a string?

e.g. How can I reference the first Member's name? Can I do it by just parsing the string, or can I treat it as an array. I've tried both and can't seem to get it ...

Many thanks.

SimpleXMLElement Object 
( 
[Member] => Array 
( 
[0] => SimpleXMLElement Object 
(
[@attributes] => Array 
( 
[name] => Meier 
[no] => 15 
[color] => 0x000000 
[info] => Trainer
) 
) 

[1] => SimpleXMLElement Object 
( 
[@attributes] => Array 
( 
[name] => Smith 
[no] => 18 
[color] => 0x045080 
[info] => Trainer
) 
) 

[2] => SimpleXMLElement Object 
( 
[@attributes] => Array 
( 
[name] => Maher 
[no] => 20 
[color] => 0x005550 
[info] => Trainer

) 
) 
) 
) 

Comments

mradcliffe’s picture

SimpleXML returns an object so if the object name were $myxml then...

echo $myxml->member[0]->attributes['name'];

Should do it right?

strands’s picture

It's strange, I would expect it to work as you mentioned, but actually

dprint_r($myxml->Member[0]['name']);

will gives Dawn what she needs ... so it seems @attributes is skipped entirely ...