Reading contents of XML/ARRAY

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rossmurphy
Forum Newbie
Posts: 5
Joined: Thu Jun 11, 2009 10:33 am

Reading contents of XML/ARRAY

Post by rossmurphy »

Hi,

I have an array called $xmlresponse and it contains this..
array(2) { ["xmlresponse"]=> object(SimpleXMLElement)#17 (2) { ["metadata"]=> object(SimpleXMLElement)#18 (1) { ["column"]=> array(4) { [0]=> object(SimpleXMLElement)#20 (1) { ["@attributes"]=> array(2) { ["datatype"]=> string(4) "text" ["name"]=> string(6) "userId" } } [1]=> object(SimpleXMLElement)#21 (1) { ["@attributes"]=> array(2) { ["datatype"]=> string(4) "text" ["name"]=> string(5) "token" } } [2]=> object(SimpleXMLElement)#22 (1) { ["@attributes"]=> array(2) { ["datatype"]=> string(4) "text" ["name"]=> string(13) "authenticated" } } [3]=> object(SimpleXMLElement)#23 (1) { ["@attributes"]=> array(2) { ["datatype"]=> string(4) "text" ["name"]=> string(10) "jsessionid" } } } } ["rows"]=> object(SimpleXMLElement)#19 (1) { ["row"]=> object(SimpleXMLElement)#24 (1) { ["@attributes"]=> array(4) { ["authenticated"]=> string(4) "true" ["jsessionid"]=> string(32) "CAF7D365B6CB63E261B283345BBB3812" ["token"]=> string(32) "p7yPE7zQWWFcYvNI6mD29yHCY7Cb0Bt2" ["userId"]=> string(6) "pleepo" } } } } ["apistring"]=> string(114) "http://192.168.0.42:8081/site-api/login ... ord=pleepo" }
I am using..

Code: Select all

$testvar = $xmlResult->rows->row['authenticated'];
To try and get the value of 'authenticated' from the xml. I am getting an error..
A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: models/dologin.php

Line Number: 21
anyone know what im doing wrong?

Thanks
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: Reading contents of XML/ARRAY

Post by mikemike »

'row' is an object, not an array. Try the following:

Code: Select all

$testvar = $xmlResult->rows->row->authenticated;
Post Reply