• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 316
  • Last Modified:

Can't parse XML response

I need help with the following xml response below:

1) Need code to assign each element as variable->$value (ie. returnCode = $returnCode)
2) Detect if element exists (ie. <olps>). I thought this would work for element detection but it does not.

                   if ( strstr($client->response, "<olps>" ) ) { echo "olps detected"; }

Running PHP 5.1.6 (cli)

Here is the response below in code section when I do:

echo '<h2>Response</h2>';
echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';

HTTP/1.1 100 Continue
Date: Sun, 10 May 2009 18:57:01 GMT
X-Powered-By: ASP.NET
HTTP/1.1 200 OK
Date: Sun, 10 May 2009 18:57:07 GMT
X-Powered-By: ASP.NET
Connection: close
Transfer-Encoding: chunked
Content-Type: text/xml;charset="utf-8"
X-Powered-By: Servlet/2.5 JSP/2.1
<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body><ns2:virtualProfile20Response xmlns:ns2="http://www.myurl.com/web-services">

Open in new window

  • 5
  • 5
1 Solution
Roger BaklundCommented:
Are you using nusoap? If you do this:

$result = $client->call(...

... then the $result variable should contain what you need. Do this:


Post the result here if you need more help.
pdheadyAuthor Commented:
Yes, am using NUSOAP. I did var_dump($result) and it's a TON of data returned in arrays (2 pages). How can i access those elements now? and do my detection?
Roger BaklundCommented:
Output this first:


Then you get the array keys on the first level only. Is 'returnCode' and 'olps' there? If not, which keys do you get? If 'olps' is there, you can access data within it like this:

$startDate = $result['olps']['startDate'];
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

pdheadyAuthor Commented:
Yes, they are there.

I'm gettting NULL for both of your examples.

Attached is the output of var_dump($result) which looks messy.
Roger BaklundCommented:
It looks like this is a dump of the entire client object, not the result... did you do this:

$return = $client->call(... your soap call here );

It looks like you did just:

$return = $client;


Roger BaklundCommented:
I wrote "$return" when I meant "$result", sorry if that was confusing. The point is that you must fetch the result of the soap call.
pdheadyAuthor Commented:
Looks like that did the trick. Here is the output now:

array(4) { ["correlationData"]=>  string(15) "CD4A08261F24496" ["etailId"]=>  string(1) "0" ["returnCode"]=>  string(2) "01" ["olps"]=>  array(6) { ["prescreenId"]=>  string(12) "874800000000" ["prescreenInd"]=>  string(1) "O" ["startDate"]=>  string(8) "20090511" ["expirationDate"]=>  string(8) "20090908" ["purgeDate"]=>  string(8) "20090908" ["creditLimit"]=>  string(4) "2500" } }

returnCode = 01
olps = Array
OLPS detected!

Let me ask you, if I am calling the $client->call SOAP object earlier in the script then put $result = $client->call(...etc) does this mean I am calling the object twice, hence hitting their web-service twice...?
$result = $client->call('themethodhere', $data, $namespace);
 $returnCode = $result['returnCode'];
 echo "<br>returnCode = $returnCode";
 $olps = $result['olps'];
 echo "<br>olps = $olps";
 if ($olps) { echo "<br>OLPS detected!"; }

Open in new window

Roger BaklundCommented:
>> does this mean I am calling the object twice, hence hitting their web-service twice...?

Yes. You should probably only do it once.
pdheadyAuthor Commented:
Ok thanks.
pdheadyAuthor Commented:
Thanks again, excellent help.....much appreciated. Have a good one.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now