cannot access SimpleXML object property
cannot access SimpleXML object property
am 07.01.2010 22:56:50 von Mari Masuda
Hi,
I am working with an XML document and have a SimpleXML object whose =
var_dump looks like this:
---
object(SimpleXMLElement)#2 (10) {
["@attributes"]=3D>
array(1) {
["id"]=3D>
string(7) "3854857"
}
["type"]=3D>
string(7) "Article"
["createDate"]=3D>
string(25) "2006-09-06T16:42:20-07:00"
["editDate"]=3D>
string(25) "2007-07-16T09:15:53-07:00"
["creator"]=3D>
string(19) "Michael Gottfredson"
["status"]=3D>
string(5) "ready"
["field"]=3D>
...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
Re: cannot access SimpleXML object property
am 07.01.2010 23:31:54 von Jonathan Tapicer
On Thu, Jan 7, 2010 at 6:56 PM, Mari Masuda wrot=
e:
> Hi,
>
> I am working with an XML document and have a SimpleXML object whose var_d=
ump looks like this:
>
> ---
> object(SimpleXMLElement)#2 (10) {
> =A0["@attributes"]=3D>
> =A0array(1) {
> =A0 =A0["id"]=3D>
> =A0 =A0string(7) "3854857"
> =A0}
> =A0["type"]=3D>
> =A0string(7) "Article"
> =A0["createDate"]=3D>
> =A0string(25) "2006-09-06T16:42:20-07:00"
> =A0["editDate"]=3D>
> =A0string(25) "2007-07-16T09:15:53-07:00"
> =A0["creator"]=3D>
> =A0string(19) "Michael Gottfredson"
> =A0["status"]=3D>
> =A0string(5) "ready"
> =A0["field"]=3D>
> =A0...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. =A0Howe=
ver, I cannot figure out how to access the value of id. =A0I tried the foll=
owing, none of which worked for me:
>
> 1. =A0$current_object->@attributes->id (gives Parse error: syntax error, =
unexpected '@', expecting T_STRING or T_VARIABLE or '{' or '$' in /Applicat=
ions/apache/htdocs/test.php on line 33)
>
> 2. =A0$current_object->'@attributes'->id (gives Parse error: syntax error=
, unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_STRING or T_VARIABLE o=
r '{' or '$' in/Applications/apache/htdocs/test.php on line 33)
>
> 3. =A0$current_object->{@attributes}->id (no error but is null)
>
> 4. =A0$current_object->{'@attributes'}->id (no error but is also null)
>
> Does anyone know how I can reference the value of id? =A0Thanks!
>
> Mari
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
$id =3D (string)$current_object['id'];
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: cannot access SimpleXML object property
am 08.01.2010 00:00:22 von Mari Masuda
On Jan 7, 2010, at 2:31 PM, Jonathan Tapicer wrote:
> On Thu, Jan 7, 2010 at 6:56 PM, Mari Masuda =
wrote:
>> Hi,
>>=20
>> I am working with an XML document and have a SimpleXML object whose =
var_dump looks like this:
>>=20
>> ---
>> object(SimpleXMLElement)#2 (10) {
>> ["@attributes"]=3D>
>> array(1) {
>> ["id"]=3D>
>> string(7) "3854857"
>> }
>> ["type"]=3D>
>> string(7) "Article"
>> ["createDate"]=3D>
>> string(25) "2006-09-06T16:42:20-07:00"
>> ["editDate"]=3D>
>> string(25) "2007-07-16T09:15:53-07:00"
>> ["creator"]=3D>
>> string(19) "Michael Gottfredson"
>> ["status"]=3D>
>> string(5) "ready"
>> ["field"]=3D>
>> ...snip a bunch of stuff...
>> }
>> ---
>>=20
>> 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:
>>=20
>> 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)
>>=20
>> 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)
>>=20
>> 3. $current_object->{@attributes}->id (no error but is null)
>>=20
>> 4. $current_object->{'@attributes'}->id (no error but is also null)
>>=20
>> Does anyone know how I can reference the value of id? Thanks!
>>=20
>> Mari
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>=20
>>=20
>=20
>=20
> $id =3D (string)$current_object['id'];
Thank you. I also found I could do it with=20
$current_object->attributes()->id=
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php