The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XML Data To PHP Variable! Help Needed!

Discussion in 'cPanel Developers' started by gamesguru, Mar 28, 2009.

  1. gamesguru

    gamesguru Member

    Joined:
    Nov 25, 2008
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    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>emailaddress@gmail.com</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!
     
  2. thobarn

    thobarn Well-Known Member

    Joined:
    Apr 25, 2008
    Messages:
    153
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    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
     
  3. gamesguru

    gamesguru Member

    Joined:
    Nov 25, 2008
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Still i am a bit confused. Can you please format this code for me?

    I have listed the xml in my thread

    Thanks!
     
  4. MattDees

    MattDees cPanel Product Owner
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    417
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    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
     
  5. gamesguru

    gamesguru Member

    Joined:
    Nov 25, 2008
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Hello All,

    Thank you.

    I figured it out.

    I used SimpleXML - It is quite simple! :)

    Thanks again
     
Loading...

Share This Page