PHP Classes

how to access individual items??

Recommend this page to a friend!

      SimpleXML for PHP4  >  All threads  >  how to access individual items??  >  (Un) Subscribe thread alerts  
Subject:how to access individual items??
Summary:what is syntax to pull out individual XML items?
Messages:2
Author:john
Date:2009-04-16 04:40:59
Update:2009-04-20 06:28:24
 

  1. how to access individual items??   Reply   Report abuse  
Picture of john john - 2009-04-16 04:40:59
Thanks for what looks like a great script.. Maybe I am too new to all this, but I just can't figure out how to actually use the class.

I get it to read my XML, and print_r($data); shows me all the info about the xml, but what do I do to actually get one specific piece of information?

What is the exact syntax to return "resultCode" from the XML below?

I think it is something along these lines, can't come up with the right combination to make this work...

$var = $item->key1->attributes();
$value = $var->name;
echo $value;

Thanks!!!

Here is what print_r($data) shows:

simplexmlobject Object
(
[@attributes] => simplexmlobject Object
(
[xmlns:xsi] => http://www.w3.org/2001/XMLSchema-instance
[xmlns:xsd] => http://www.w3.org/2001/XMLSchema
[xmlns] => AnetApi/xml/v1/schema/AnetApiSchema.xsd
)

[messages] => simplexmlobject Object
(
[resultCode] => Error
[message] => simplexmlobject Object
(
[code] => E00039
[text] => A duplicate record with id 360721 already exists.
)

)

)

  2. Re: how to access individual items??   Reply   Report abuse  
Picture of Taha Paksu Taha Paksu - 2009-04-20 06:28:24 - In reply to message 1 from john
i assume that you are not interested in getting the xmlns: header datas and just to get the messages from your xml file. Ok,

You can get the code line by : $data->messages->resultCode;

And the values in the message tag :
$data->messages->message->code;
$data->messages->message->text;

they should work.