Re: cannot access SimpleXML object property

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jan 7, 2010 at 6:56 PM, Mari Masuda <mari.masuda@xxxxxxxxxxxx> wrote:
> Hi,
>
> I am working with an XML document and have a SimpleXML object whose var_dump looks like this:
>
> ---
> object(SimpleXMLElement)#2 (10) {
>  ["@attributes"]=>
>  array(1) {
>    ["id"]=>
>    string(7) "3854857"
>  }
>  ["type"]=>
>  string(7) "Article"
>  ["createDate"]=>
>  string(25) "2006-09-06T16:42:20-07:00"
>  ["editDate"]=>
>  string(25) "2007-07-16T09:15:53-07:00"
>  ["creator"]=>
>  string(19) "Michael Gottfredson"
>  ["status"]=>
>  string(5) "ready"
>  ["field"]=>
>  ...snip a bunch of stuff...
> }
> ---
>
> Assuming the above object is referenced by $current_object, I can access the values of most stuff with $current_object->creator or whatever.  However, I cannot figure out how to access the value of id.  I tried the following, none of which worked for me:
>
> 1.  $current_object->@attributes->id (gives Parse error: syntax error, unexpected '@', expecting T_STRING or T_VARIABLE or '{' or '$' in /Applications/apache/htdocs/test.php on line 33)
>
> 2.  $current_object->'@attributes'->id (gives Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_STRING or T_VARIABLE or '{' or '$' in/Applications/apache/htdocs/test.php on line 33)
>
> 3.  $current_object->{@attributes}->id (no error but is null)
>
> 4.  $current_object->{'@attributes'}->id (no error but is also null)
>
> Does anyone know how I can reference the value of id?  Thanks!
>
> Mari
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


$id = (string)$current_object['id'];

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux