1

If I have a raw XML message that I need to pass in PHP, is there an easy way to pass it?

Something like this:

$xml = '
<?xml version="1.0"?>

<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">

  <soap:Header>
    ...
  </soap:Header>

  <soap:Body>
  ...
    <soap:Fault>
    ...
    </soap:Fault>
  </soap:Body>

</soap:Envelope>';

$url = 'http://www.myurl.com';

passXmlToSoap($xml,$url);

I am not trying to master using SOAP and I only need to use it to do a very simple thing so I am hoping that I can use raw XML and do it as simply as possible even though that might not be "the right way" to do it.

Andri
  • 453
  • 4
  • 22

2 Answers2

1

check this answer: How to parse SOAP XML? there should be libraries for parsing XML, but that answer gives you an straightforward way to do it. Good Luck it works:

$xml = '<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Header>
<Name>Yo</Name>
 </soap:Header>
  <soap:Body>
      <payment>
        <uniqueReference>ESDEUR11039872</uniqueReference>      
        <epacsReference>74348dc0-cbf0-df11-b725-001ec9e61285</epacsReference>
        <postingDate>2010-11-15T15:19:45</postingDate>
        <bankCurrency>EUR</bankCurrency>
        <bankAmount>1.00</bankAmount>
        <appliedCurrency>EUR</appliedCurrency>
        <appliedAmount>1.00</appliedAmount>
        <countryCode>ES</countryCode>
        <bankInformation>Sean Wood</bankInformation>
       <merchantReference>ESDEUR11039872</merchantReference>
   </payment>
  </soap:Body>
</soap:Envelope>';


$xml = simplexml_load_string($xml);
print_r( $xml) ;

$xml->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');
foreach ($xml->xpath('//payment') as $item)
{
    print_r($item);
}
Community
  • 1
  • 1
  • Thank you. But... and excuse me if this is a stupid question... where would the URL to the web service go (I'm not completely sure if I should use url to WDSL, url to SOAP or Service URL but I'm pretty sure there should be an url to one of those somewhere)? – Andri Feb 15 '17 at 03:30
  • well, that XML string can come from a request you made to an external service using, for instance, CURL as in this example http://stackoverflow.com/questions/11553678/read-xml-data-from-url-using-curl-and-php – user7544423 Feb 15 '17 at 06:42
  • however, if you are trying to send XML to a service, check this answer too http://stackoverflow.com/questions/8805061/php-soap-http-request – user7544423 Feb 15 '17 at 06:44
-1

In any case you should never have to parse XML response nor pass XML request to consume SOAP Web Service.

First if you use the native php SoapClient class you send an object or an array. Then you receive stdClass objects

Second, you should use a WSDL to php generator that generates classes mathing the parameters that has to be sent. It also generated the classes that match the response object. Finally, it generated the classes to send the request. So you can send the request and receive the response very easily without any doubt and without having to deal with XML.

Try PackageGenerator project.

Mikaël DELSOL
  • 760
  • 5
  • 15