Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Member
    Join Date
    Nov 2008
    Posts
    6

    Question XML Data To PHP Variable! Help Needed!

    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. #2
    Member
    Join Date
    Apr 2008
    Location
    sanctum sanctorum
    Posts
    152

    Default

    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. #3
    Member
    Join Date
    Nov 2008
    Posts
    6

    Default

    Quote Originally Posted by thobarn View Post
    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!

  4. #4
    cPanel Staff cPanelMatt's Avatar
    Join Date
    Apr 2005
    Location
    Houston, TX
    Posts
    409

    Default

    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
    Matt Dees
    Integration Developer
    cPanel, Inc.
    cPanel Integration Blog

  5. #5
    Member
    Join Date
    Nov 2008
    Posts
    6

    Default

    Quote Originally Posted by cPanelMatt View Post
    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

Similar Threads & Tags
Similar threads

  1. Locate line variable in JSON dumpzone data
    By mikelegg in forum cPanel Developers
    Replies: 8
    Last Post: 06-08-2011, 07:55 AM
  2. Empty @_GET variable = how to change max variable length?
    By JmsCrk in forum cPanel and WHM Discussions
    Replies: 5
    Last Post: 05-09-2011, 10:06 AM
  3. want test script for html fetching data from xml file
    By its_joe in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 01-25-2009, 06:43 AM
  4. xml data does not display
    By pola090 in forum Database Discussions
    Replies: 1
    Last Post: 10-27-2007, 06:17 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube