Search code examples
phpweb-servicessoapwsdlsoap-client

SoapClient returns one long string


Here is the WSDL format:

http://www.petango.com/webservices/wsadoption.asmx?WSDL

I am using the developer-provided test server which says that it will return a SOAP response in the following XML format:

<ArrayOfXmlNode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.petango.com/">

<!-- Animal 1 // -->
<XmlNode>
<adoptableSearch xmlns="">
<ID>10270740</ID>
<Name>Peyton</Name>
<Species>Dog</Species>
<Sex>Male</Sex>
</adoptableSearch>
</XmlNode>

...

<!-- Animal n - 1 // -->
<XmlNode>
<adoptableSearch xmlns="">
<ID>4252534</ID>
<Name>Chilli</Name>
<Species>Dog</Species>
<Sex>Male</Sex>
</adoptableSearch>
</XmlNode>

</ArrayOfXmlNode>

I set up the SOAP call:

$wsdl = 'http://www.petango.com/webservices/wsadoption.asmx?WSDL';
$client = new SoapClient($wsdl);

$params = array(
  'authkey' => 'myauthkey',
  'speciesID' => '',  
  'sex' => '',
  'ageGroup' => '',
  'location' => '',
  'site' => '',
  'onHold' => '',
  'orderBy' => '',
  'primaryBreed' => '',
  'secondaryBreed' => '',
  'specialNeeds' => '',
  'noDogs' => '',
  'noCats' => '',  
  'noKids' => '',
  'stageID' => ''
);

$result = $client->AdoptableSearch($params);

Then I print it out:

echo print_r($result, true);

When I view the source, I get:

stdClass Object
(
  [AdoptableSearchResult] => stdClass Object
    (
      [XmlNode] => Array
        (
          [0] => stdClass Object
            (
              [any] => <adoptableSearch xmlns=""><ID>10270740</ID><Name>Peyton</Name><Species>Dog</Species><Sex>Male</Sex></adoptableSearch>
            )
          [1] => stdClass Object
        (
          [any] => <adoptableSearch xmlns=""><ID>10270740</ID><Name>Peyton</Name><Species>Dog</Species><Sex>Male</Sex></adoptableSearch>
        )
...

As you can see, everything is returned as expected until we get to the actual details of the animal. At that point, the result is one long XML string under the any property. Where is the any property coming from and why are the animal details not broken up into separate properties or keys like the result of xml nodes?


Solution

  • it is any because In WSDL file response of adoptableSearch contain any type.

    <s:element minOccurs="0" maxOccurs="unbounded" name="XmlNode" nillable="true">
    <s:complexType mixed="true">
    <s:sequence>
    <s:any/>
    </s:sequence>
    </s:complexType>
    

    You can use this php method to convert string xml into array object.

    simplexml_load_string [http://php.net/manual/en/function.simplexml-load-string.php]