XML API accessing response data
Hi Guys,
Im pretty sure im having a slow day but i cant for the life of me seem to get the data out of the responce object.
[PHP]
print "
however, i cant access any of those in PHP. i've tried all sorts, from accessing the properties directly: [PHP] print($username->acct->user); [/PHP] to looping over it: [PHP] foreach($ar13bakk->acct as $key => $account){ print_r($account->user); } [/PHP] which gives:
and i still cant access that. I've tried looping over it, i've also tried accessing the object key ($account->user{'0'}) no joy ether. So, what on earth am i missing?
"; print_r($xmlapi->accountsummary('username')); print ""; [/PHP] spits out something like this:
SimpleXMLElement Object
(
[acct] => SimpleXMLElement Object
(
[backup] => 0
[disklimit] => 2000M
[diskused] => 372M
[domain] => ***
=> ***
[ip] => ***
[is_locked] => 0
[legacy_backup] => 1
[max_defer_fail_percentage] => unlimited
[max_email_per_hour] => unlimited
[maxaddons] => *unknown*
[maxftp] => unlimited
[maxlst] => unlimited
[maxparked] => 2
[maxpop] => unlimited
[maxsql] => unlimited
[maxsub] => unlimited
[min_defer_fail_to_trigger_protection] => 5
[owner] => ***
[partition] => home
[plan] => Standard
[shell] => /usr/local/cpanel/bin/noshell
[startdate] => 14 Feb 14 15:58
[suspended] => 0
[suspendreason] => not suspended
[suspendtime] => SimpleXMLElement Object
(
)
[theme] => x3
[unix_startdate] => 1392393516
[user] => ***
)
[status] => 1
[statusmsg] => Ok
)
however, i cant access any of those in PHP. i've tried all sorts, from accessing the properties directly: [PHP] print($username->acct->user); [/PHP] to looping over it: [PHP] foreach($ar13bakk->acct as $key => $account){ print_r($account->user); } [/PHP] which gives:
SimpleXMLElement Object
(
[0] => ar13bakk
)
and i still cant access that. I've tried looping over it, i've also tried accessing the object key ($account->user{'0'}) no joy ether. So, what on earth am i missing?
-
right. After much messing about i descovered why this wasnt working. The data inside the object is also stored as an object. so for example, inside the origonal print_t() we had this: SimpleXMLElement Object ( [acct] => SimpleXMLElement Object ( [backup] => 0 [disklimit] => 2000M [diskused] => 372M [domain] => *** => *** [ip] => *** [is_locked] => 0 [legacy_backup] => 1 [max_defer_fail_percentage] => unlimited [max_email_per_hour] => unlimited [maxaddons] => *unknown* [maxftp] => unlimited [maxlst] => unlimited [maxparked] => 2 [maxpop] => unlimited [maxsql] => unlimited [maxsub] => unlimited [min_defer_fail_to_trigger_protection] => 5 [owner] => *** [partition] => home [plan] => Standard [shell] => /usr/local/cpanel/bin/noshell [startdate] => 14 Feb 14 15:58 [suspended] => 0 [suspendreason] => not suspended [suspendtime] => SimpleXMLElement Object ( ) [theme] => x3 [unix_startdate] => 1392393516 [user] => *** ) [status] => 1 [statusmsg] => Ok )
so the structure would normally be something like $account(object)->acct(object)->disklimit(object)->2000M(string) infact whats happening is that the values are also objects. The end result is that when attempting to access those values you instead key a key'd object, hence the:SimpleXMLElement Object ( [0] => ar13bakk )
to resolve the issue for now you can typecast with [PHP] $disklimit = (string)$account->acct->disklimit; [/PHP] hardly ideal but it works for now. If i get a chance, i'll see about posting a more perminent solution0 -
Hello :) Thank you for updating the thread with an initial solution to the problem you presented. Thank you. 0
Please sign in to leave a comment.
Comments
2 comments