FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Interpret SimpleXMLElement Object
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Interpret SimpleXMLElement Object [message #170141] Tue, 12 October 2010 14:22 Go to next message
Vinicius Nez is currently offline  Vinicius Nez
Messages: 2
Registered: October 2010
Karma: 0
Junior Member
hi,

how to save [token] on $new_token,

i tried using foreach but i didn't get to reach to the [token]

SimpleXMLElement Object ( [@attributes] => Array ( [stat] => ok )
[auth] => SimpleXMLElement Object ( [token] => qweqwe [perms] =>
delete [user] => SimpleXMLElement Object ( [@attributes] => Array
( [nsid] => qweqwe234 [username] => qweqweqwe [fullname] =>
asdasdasd ) ) ) )
Re: Interpret SimpleXMLElement Object [message #170142 is a reply to message #170141] Tue, 12 October 2010 14:33 Go to previous messageGo to next message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.oO(Vinicius Núñez)

> how to save [token] on $new_token,
>
> i tried using foreach but i didn't get to reach to the [token]
>
> SimpleXMLElement Object ( [@attributes] => Array ( [stat] => ok )
> [auth] => SimpleXMLElement Object ( [token] => qweqwe [perms] =>
> delete [user] => SimpleXMLElement Object ( [@attributes] => Array
> ( [nsid] => qweqwe234 [username] => qweqweqwe [fullname] =>
> asdasdasd ) ) ) )

It would be helpful to keep the formatting of a var_dump() output. If
you just print this to an HTML page, wrap it in <pre>...</pre> tags.

I've done some wrapping by hand to make the structure more readable:

SimpleXMLElement Object (
[@attributes] => Array (
[stat] => ok
)
[auth] => SimpleXMLElement Object (
[token] => qweqwe
[perms] => delete
[user] => SimpleXMLElement Object (
[@attributes] => Array (
[nsid] => qweqwe234
[username] => qweqweqwe
[fullname] => asdasdasd
)
)
)
)

Given that, you can access the 'token' element with this:

$new_token = $yourXml->auth->token;

Dependent on the usage you might also have to cast the value to string:

$new_token = (string)$yourXml->auth->token;

Have a look at the manual to read more about the SimpleXML syntax and
how to access the various elements in an XML tree.

Micha
Re: Interpret SimpleXMLElement Object [message #170161 is a reply to message #170142] Wed, 13 October 2010 14:14 Go to previous message
Vinicius Nez is currently offline  Vinicius Nez
Messages: 2
Registered: October 2010
Karma: 0
Junior Member
On 12 out, 11:33, Michael Fesser <neti...@gmx.de> wrote:
> .oO(Vinicius Núñez)
>
>> how to save [token] on $new_token,
>
>> i tried using foreach but i didn't get to reach to the [token]
>
>> SimpleXMLElement Object ( [@attributes] => Array ( [stat] => ok )
>> [auth] => SimpleXMLElement Object ( [token] => qweqwe [perms] =>
>> delete [user] => SimpleXMLElement Object ( [@attributes] => Array
>> ( [nsid] => qweqwe234 [username] => qweqweqwe [fullname] =>
>> asdasdasd ) ) ) )
>
> It would be helpful to keep the formatting of a var_dump() output. If
> you just print this to an HTML page, wrap it in <pre>...</pre> tags.
>
> I've done some wrapping by hand to make the structure more readable:
>
> SimpleXMLElement Object (
>   [@attributes] => Array (
>     [stat] => ok
>   )
>   [auth] => SimpleXMLElement Object (
>     [token] => qweqwe
>     [perms] => delete
>     [user] => SimpleXMLElement Object (
>       [@attributes] => Array (
>         [nsid] => qweqwe234
>         [username] => qweqweqwe
>         [fullname] => asdasdasd
>       )
>     )
>   )
> )
>
> Given that, you can access the 'token' element with this:
>
> $new_token = $yourXml->auth->token;
>
> Dependent on the usage you might also have to cast the value to string:
>
> $new_token = (string)$yourXml->auth->token;
>
> Have a look at the manual to read more about the SimpleXML syntax and
> how to access the various elements in an XML tree.
>
> Micha

Thanks!
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: problem with session cleanup
Next Topic: How to Hide browser status bar Message from client
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 18:44:12 GMT 2024

Total time taken to generate the page: 0.02348 seconds