php - How to parse SOAP XML? -
soap xml:
<?xml version="1.0" encoding="utf-8"?> <soap:envelope xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:body> <paymentnotification xmlns="http://apilistener.envoyservices.com"> <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> </paymentnotification> </soap:body> </soap:envelope>
how 'payment' element?
i try parse (php)
$xml = simplexml_load_string($soap_response); $xml->registerxpathnamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/'); foreach ($xml->xpath('//payment') $item) { print_r($item); }
result empty :( ideas how parse correct?
one of simplest ways handle namespace prefixes strip them xml response before passing through simplexml such below:
$your_xml_response = '<your xml here>'; $clean_xml = str_ireplace(['soap-env:', 'soap:'], '', $your_xml_response); $xml = simplexml_load_string($clean_xml);
this return following:
simplexmlelement object ( [body] => simplexmlelement object ( [paymentnotification] => simplexmlelement object ( [payment] => simplexmlelement object ( [uniquereference] => esdeur11039872 [epacsreference] => 74348dc0-cbf0-df11-b725-001ec9e61285 [postingdate] => 2010-11-15t15:19:45 [bankcurrency] => eur [bankamount] => 1.00 [appliedcurrency] => eur [appliedamount] => 1.00 [countrycode] => es [bankinformation] => sean wood [merchantreference] => esdeur11039872 ) ) ) )
Comments
Post a Comment