I’m having trouble accessing the child nodes of my SimpleXML content. I’ve tried a few variations like $xmlData->id or $xmlData['id'].
I’m somewhat new to this area, so any help would be greatly appreciated.
Code sample:
$xmlData = simplexml_load_string($string);
$person = $xmlData->documentElement;
$id = $xmlData->id;
Var dump of $xmlData from Simple XML:
object(SimpleXMLElement)#23 (10) {
["id"]=> string(10) "yTZn1JIaaa"
["first-name"]=> string(6) "First Name"
["last-name"]=> string(6) "Last Name"...
I tried to rebuild your snippet:
This worked fine for me – the Output was:
You can see, that my firstname and lastname tagnames are different to yours – the dash sometimes causes troubles. If you need the dash, do it this way instead:
Anyways, the
idworked fine…so maybe you have another error that prevents your scripts from running properly? Maybe it would be helpful if you could post your XML-String.Cheers,
Max
P.S.: Why are you executing this line?