April 27th, 2013, 02:09 AM
Web Service response handling
Can pls anyone help on the following problem?
I am writting an application that consumes several web services, using SoapClient or cURL client.
The problem is that the response of one of these services is really weird... From the server-side specs the response should be a defined object. From my client side of view, the response is a string of an xml.
In my code :
$client = SoapClient(...);
$result = $client->myMethod();
$result = curl_exec(...)
- when I use: "echo $result", the output is a string with only tag values displayed sequentially
- when I use: "var_dump($result)", the result is an empty object!
- when I use: "echo htmlentities($result)", the output is the xml response
- I have also tried to convert this string (of xml) to an array, using SimpleXML, but it resulted in an empty array...
My question is how such a response can be handled! I want to be able to retrieve specific values by i.e. $result->item, and not by parsing the string (even this is not easily possible since the tags in a string have strange behaviour)
Can someone give any idea?
Thanks a lot
April 27th, 2013, 10:32 AM
Using SimpleXML is the right approach. SimpleXML shouldn't have returned an array at all, it deals primarily with objects, so I don't quite follow you there. Try posting an example of your code using SimpleXML.
April 27th, 2013, 03:11 PM
Indead, the simplexml returned me an empty object.
Lets say that the $result has my response.
echo $result; --> prints out the tag values only, sequentially
echo htmlentities($result) --> prints out the xml response
Then, I tried :
$xml = simplexml_load_string($result);
echo $xml; --> unsuccessful
var_dump($xml); --> empty object
Also, I have tried
$xml = simplexml_load_string( htmlentities($result) );
with no result.
I guess I am doing something really wrong
Originally Posted by E-Oreo
April 27th, 2013, 03:17 PM
Also, I try to remove the
<?xml version="1.0" encoding="utf-8" ?>
part of the $result (which is the xml response string) by using the str_replace(). I think that I am messed up. The $result is a string with the xml response in it, but tags are can not be handled by string functions?
Originally Posted by tsetse13