PЯINCƎ
PЯINCƎ

Reputation: 724

simplexml_load_string() expects parameter 1 to be string when parse this Soap xml

I tried the solutions of How to parse this SOAP XML response with PHP simplexml_load_string?, but it doesn't work.

Maybe someone have an idea to how to parse this Soap XML result, you find the soap.xml and result and the test

Soap.xml

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" ...>
    <wsdl:documentation>soapExemple</wsdl:documentation>
    <wsdl:types>
        <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://.../xsd">
...

Output:

<?php
    ini_set("soap.wsdl_cache_enabled", "0");
    const USER = "userHere";
    const PASSWORD = "passHere";
    $credentials = array('login' => USER, 'password' => PASSWORD);
    $options = array("trace" => 1, "exception" => 0, 'encoding' => 'UTF-8');
    $url = "pass/to/wsdl.xml";
    $soap = new SoapClient($url, $credentials);
    var_dump($soap);

    try {
        $result = $soap->__soapCall("reclis_XML", array("parameters"=>array("args0"=>array("METHODHERE" => "01"))));
        var_dump($result);
    } catch (SoapFault $exception) {
        \Zend_Debug::dump( 'Exception Thrown: '.$exception->faultstring);
    }

?>

Result:

object(stdClass)#6591 (1) {
  ["return"] => string(39171) "<?xml version="1.0" encoding="UTF-8"?>
<RECLIS>
  <RESULT>KO</RESULT>
  <REAL>0</REAL>
  <RUS>
    <REAL>0</REAL>
    <CUSTOMER>
      <CLEMAJ></CLEMAJ>
      <NAME></NAME>
      <LASTNALE>0</LASTNALE>
      <PHONE>0</PHONE>
      <AD></AD>
      <ADDRESS1></ADDRESS1>
      <ADDRESS2></ADDRESS2>
      <CITY></CITY>
      <CODE></CODE>
      <PRICE>0</PRICE>
    </CUSTOMER>
    <CUSTOMER>
      <CLEMAJ></CLEMAJ>
      <NAME></NAME>
      <LASTNALE>0</LASTNALE>
      <PHONE>0</PHONE>
      <AD></AD>
      <ADDRESS1></ADDRESS1>
      <ADDRESS2></ADDRESS2>
      <CITY></CITY>
      <CODE></CODE>
      <PRICE>0</PRICE>
    </CUSTOMER>
    <CUSTOMER>
      <CLEMAJ></CLEMAJ>
      <NAME></NAME>
      <LASTNALE>0</LASTNALE>
      <PHONE>0</PHONE>
      <AD></AD>
      <ADDRESS1></ADDRESS1>
      <ADDRESS2></ADDRESS2>
      <CITY></CITY>
      <CODE></CODE>
      <PRICE>0</PRICE>
    </CUSTOMER>
    ...
  </RUS>
</RECLIS>
"
}

I tried this but it doesn't work:

$xml=simplexml_load_string($myXMLData) or die("Error: Cannot create object");
print_r($xml);

Have you an idea or another solution to get my xml result as an array

Upvotes: 2

Views: 1908

Answers (1)

The fourth bird
The fourth bird

Reputation: 163467

You have to get the string by accessing the return property

Try using:

$xml=simplexml_load_string($myXMLData->return) or die("Error: Cannot create object");
print_r($xml);

Upvotes: 1

Related Questions