#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    1
    Rep Power
    0

    Web Service response handling


    Hello ppl,

    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();
    OR
    $result = curl_exec(...)

    Result :
    - 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
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    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.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    4
    Rep Power
    0
    Thanks Oreo!

    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
    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.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    4
    Rep Power
    0
    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
    Thanks Oreo!

    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

IMN logo majestic logo threadwatch logo seochat tools logo