adamf321
adamf321

Reputation: 179

simplexml_load_string doesn't work with soap response

I'm trying to parse the xml response from a soap service. However, I can't get simplexml_load_string to work! Here is my code:

//make soap call
objClient = new SoapClient('my-wsdl',
    array('trace' => true,'exceptions' => 0, 'encoding' => 'UTF-8'));
$soapvar = new SoapVar('my-xml', XSD_ANYXML);
$objResponse = $objClient->__soapCall($operation, array($soapvar));

//process result
$str_xml = $objClient->__getLastResponse();
$rs_xml = simplexml_load_string($str_xml);

...$rs_xml always has just one element with name Envelope.

However, if I use *"print var_export($objClient->__getLastResponse(),true);"* to dump the result to my browser, then cut and paste it into my code as a string variable, it work fine! This is what I mean:

$str_xml = 'my cut and pasted xml';
$rs_xml = simplexml_load_string($str_xml);

So it seems the problem is somehow related to something $objClient->__getLastResponse() is doing to the string it creates... but I'm at a loss as to what the problem is or how to fix it.

Upvotes: 2

Views: 763

Answers (1)

Robbie
Robbie

Reputation: 17710

Do the following:

$str_xml = $objClient->__getLastResponse();    
$str_xml = strstr($str_xml, '<');
$rs_xml = simplexml_load_string($str_xml);

As it's a quick and easy hack to strip off stuff before the first opening element.

Upvotes: 1

Related Questions