Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Aug 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    parsing file passed as a string

    I've been given code that returns an XML string. The string has one root element and all of the other elements are in the next level. I don't know how to process it, pull the data out and store in variables, for example.

    I don't know what version of PHP. If necessary, how do I find out?


    Thanks in advance!

    PHP Code:
    <?php
    $ch 
    curl_init();
    curl_setopt($chCURLOPT_URL"http://xxxxxxxx.com/XML.php");
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
    curl_setopt($chCURLOPT_POSTtrue);
    $data $_POST;
    $domain $_SERVER['HTTP_HOST'];
    $domain str_replace('http://www.'''$domain);
    $domain str_replace('http://'''$domain);
    $domain str_replace('www.'''$domain);
    $data['domainName'] = $domain;
    curl_setopt($chCURLOPT_POSTFIELDS$data);
    $output curl_exec($ch);
    curl_close($ch);

    // $output has the XML Data returned from my calculation

    //*******
    // Above: code provided to me.  Below result:  "Fatal Error: Call to undefined function"  
    //*******

    var_dump($output);

    $calculation SimpleXMLElement($output);
    ?>

    The result is:

    Code:
    string(2095) "<?xml version="1.0" encoding="UTF-8"?>
    <Calculation><financeType>purchase</financeType><purchasePrice>412432</purchasePrice><loanAmount>244</loanAmount><county>69</county><city>69</city></Calculation>"
    <br />
    <b>Fatal error</b>:  Call to undefined function: simplexmlelement() in <b>/home/vg008web03/26/52/2905226/web/action.php</b> on line <b>20</b><br />
    Last edited by Lamped; 08-18-2012 at 01:22 AM. Reason: Corrected tags

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You should find a tutorial to teach you how to handle XML files using PHP. Here's the first one I found on Google and it looks quite nice:

    http://www.phpfreaks.com/tutorial/handling-xml-data

    Also, the PHP manual at php.net is a great resource.

    http://us3.php.net/manual/en/simplex...ples-basic.php

    Good luck!

  • #3
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    Replace:

    PHP Code:
    $calculation SimpleXMLElement($output); 
    With:

    PHP Code:
    $calculation simplexml_load_string($output); 
    You might beable to use "new SimpleXMLElement($output)" but I've not tried. The point here is that creating a new object would need "new" infront of it.
    Last edited by Lamped; 08-18-2012 at 01:26 AM. Reason: Extra info
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog

  • Users who have thanked Lamped for this post:

    umopap!sdn (08-18-2012)

  • #4
    New to the CF scene
    Join Date
    Aug 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    The guy who sent me the code was too busy to help me out so I really appreciate your reply. The guy thought my problem was that I don't have the correct version of PHP installed.

    And contrary to what other people might think, I am trying to figure it out on my own. I had already tried both of your suggestions, (1) $calculation = simplexml_load_string($output); yields the same error. (2) new SimpleXMLElement($output); yields "Cannot instantiate non-existent class: simplexmlelement"

    I've been looking for sample code that would parse the data but all I've found so far was code that parses a file and not the string.

  • #5
    New to the CF scene
    Join Date
    Aug 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I found this somewhere else. It was suggested that I add this line to my .htaccess file:

    AddHandler x-mapp-php5 .php

    It didn't help.

  • #6
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    You must use simplexml_load_string($output) and I doubt you need the AddHandler.

    What error is it giving with simplexml_load_string($output)? Give us the whole error text.
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog

  • #7
    New to the CF scene
    Join Date
    Aug 2012
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks, The error message is:
    <b>Fatal error</b>: Call to undefined function: simplexmlelement() in <b>/home/vg008web03/26/52/2905226/web/action.php</b> on line <b>20</b><br />

    ...And that looks like is because I have PHP 4.4.9 installed. I'm afraid to upgrade to 5 because I don't want to have to fix anything that is already running fine.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •