0

I am new to php an XML. Plus I have gone through many threads on this topic here.

There might be a slight glitch, but I am not able to read this.

Here is what I am doing to read it as per one of the threads.

        //parse xml string into SimpleXML objects
        $returnxml = simplexml_load_string($result);

        if ($returnxml === false) {
            die('Error parsing Return XML');
        }

        //now we can loop through the xml structure
        foreach ($returnxml->channel->item as $item) {
            print $item->title;
        }

I do not get anything using above code

Here is the actual [EXACT] XML response using CURL

<?xml version="1.0" encoding="ISO-8859-1"?>
&lt;ncresponse

orderID="120130414021640"

PAYID="BESALDOM 516A65F5E5E"

STATUS="4"

NCSTATUS="0"

NCERROR=""

NCERRORPLUS="Your transaction has been submitted for processing."

ACCEPTANCE="BINF-"

IPCTY=""

CCCTY=""

IDUsager="7884TSMA"

/&gt;

Next this is the CURL Code I am using, which looks fairly ok.

    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL, $this->omnipayment_action_url);
    curl_setopt($ch,CURLOPT_POST, count($myorder));
    curl_setopt($ch,CURLOPT_POSTFIELDS, $flds);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    $result = curl_exec($ch);
    curl_close($ch);

Thanks in advance, any help will be much appreciated...

3
  • The return xml is one node and you trying to loop it using $returnxml->channel - where do you see in the response channel ? Commented Apr 14, 2013 at 10:08
  • @aditi : I have no idea what you are saying. I just want to read this particular xml. Commented Apr 14, 2013 at 10:25
  • please double check the formatting of the part you call the exact curl response. Make yourself comfortable with the editing tools a bit more, in the current form how your question is, it's not really clear if that is XML or not or what not. Commented Apr 14, 2013 at 19:09

2 Answers 2

1

As Adidi rightly pointed out, you're not trying to obtain the information supplied to you from the right location. The information you need is in the root node and stored as attributes, here's a quick example showing how to get those:-

<?php
function parse_response($response) {
    $xml = new SimpleXMLElement($response);
    $arr = array();
    foreach($xml->attributes() as $key => $value) {
        $arr[(string)$key] = (string)$value;
    }
    return $arr;
}

var_dump(parse_response($str));
/*
    array(10) {
      ["orderID"]=>
      string(15) "120130414021640"
      ["PAYID"]=>
      string(20) "BESALDOM 516A65F5E5E"
      ["STATUS"]=>
      string(1) "4"
      ["NCSTATUS"]=>
      string(1) "0"
      ["NCERROR"]=>
      string(0) ""
      ["NCERRORPLUS"]=>
      string(51) "Your transaction has been submitted for processing."
      ["ACCEPTANCE"]=>
      string(5) "BINF-"
      ["IPCTY"]=>
      string(0) ""
      ["CCCTY"]=>
      string(0) ""
      ["IDUsager"]=>
      string(8) "7884TSMA"
    }
*/
Sign up to request clarification or add additional context in comments.

3 Comments

It does work, try harder. Are you obtaining the response as a string and passing it into the parse_response function?
I am passing whatever CURL responded back with in $result. I did not add any conversion function. Next I tried to use your function as is and it does not even dump anything like your example does.
Finally it worked. The response was not even an xml. I read it like string and the results came in. Thanks for your help
0

simple load xml file ..

<?php
$xml = @simplexml_load_string($result);

$status = (string)$xml->Status; 
$operator_trans_id = (string)$xml->OPID;
$trns_id = (string)$xml->TID;

1 Comment

use response which is returned by Curl function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.