XML Data To PHP Variable! Help Needed!

gamesguru

Member
Nov 25, 2008
6
0
51
Hello,

When i try to list information from an account i am getting reply back in XML format.

<accountsummary>

<acct>
<disklimit>999999M</disklimit>
<diskused>2083M</diskused>
  • <domain>domain.com</domain>
  • <email>[email protected]</email>
  • <ip>192.168.1.1</ip>
  • <owner>resellername</owner>
  • <partition>home</partition>
  • <plan>ul</plan>
  • <startdate>09 Mar 02 14:30</startdate>
  • <suspended>0</suspended>
  • <suspendreason>not suspended</suspendreason>
  • <theme>x3</theme>
  • <unix_startdate>1220383821</unix_startdate>
  • <user>username</user>
  • </acct>
  • <status>1</status>
  • <statusmsg>Ok</statusmsg>
  • </accountsummary>
  • <!--
  • Web Host Manager (c) cPanel, Inc. 2008 http://cpanel.net/ Unauthorized copying is prohibited.
-->

I want to use XML API only (dont want to use /script/blah!blah!)

I think SimpleXML will work out!

But it seems to be a bit hard. Please tell me a way the get this data into a variable like.

$domain = xml_array(domain);
$email = xml_array(email);
$plan = xml_array(plan);

echo "

Account Information:

Domain: $domain
Email: $email
Plan: $plan

";

Guys Please help me to do something like this.....

Thanks in advance!
 

thobarn

Well-Known Member
Apr 25, 2008
152
1
68
sanctum sanctorum
You are basically trying to parse XML. You can use PHP's XML parsing capability to parse whatever you need. Here is a simple example from PHP documentation
Code:
<?php
$simple = "<para><note>simple note</note></para>";
$p = xml_parser_create();
xml_parse_into_struct($p, $simple, $vals, $index);
xml_parser_free($p);
echo "Index array\n";
print_r($index);
echo "\nVals array\n";
print_r($vals);
?>
Look at the xml_parse function for a more elaborate example. More info is available in PHP documentation
 

gamesguru

Member
Nov 25, 2008
6
0
51
You are basically trying to parse XML. You can use PHP's XML parsing capability to parse whatever you need. Here is a simple example from PHP documentation
Code:
<?php
$simple = "<para><note>simple note</note></para>";
$p = xml_parser_create();
xml_parse_into_struct($p, $simple, $vals, $index);
xml_parser_free($p);
echo "Index array\n";
print_r($index);
echo "\nVals array\n";
print_r($vals);
?>
Look at the xml_parse function for a more elaborate example. More info is available in PHP documentation
Still i am a bit confused. Can you please format this code for me?

I have listed the xml in my thread

Thanks!
 

MattDees

Well-Known Member
Apr 29, 2005
416
1
243
Houston, TX
cPanel Access Level
Root Administrator
I think you're trying to parse the simpleXML incorrectly:

$result = simplexml_load_string($http_response)
print $result->result->rawout;

would print the rawout from the XML result. see http://us.php.net/simplexml for more info (look at the code examples)

Also, you might want to check out the XMLAPI php class I wrote which has most of this stuff already implemented in it: http://forums.cpanel.net/showthread.php?t=111897
 

gamesguru

Member
Nov 25, 2008
6
0
51
I think you're trying to parse the simpleXML incorrectly:

$result = simplexml_load_string($http_response)
print $result->result->rawout;

would print the rawout from the XML result. see http://us.php.net/simplexml for more info (look at the code examples)

Also, you might want to check out the XMLAPI php class I wrote which has most of this stuff already implemented in it: http://forums.cpanel.net/showthread.php?t=111897
Hello All,

Thank you.

I figured it out.

I used SimpleXML - It is quite simple! :)

Thanks again