i have problem extracting information soap response. hte response get:
<?xml version="1.0" encoding="utf-8" ?> - <soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"> - <soap:body> - <getinfofromsendingresponse xmlns="http://test.test.com/"> <getinfofromsendingresult>{"sendingid":"2468","subject":"test","id":"2468","campaignid":"890","forwardaddress":"test@test.ro","sendingtime":"1/14/2016 8:00:00 am","sendleadstoemail":"0","languageid":"6","leadstestmode":true,"webversionlink":"","language":"fr"}</getinfofromsendingresult> </getinfofromsendingresponse> </soap:body> </soap:envelope>
i need information getinfofromsendingresult
, store in variable can use information.
example: change language of form based on "language"
info provided in soap response. appreciated.
another possible solution use example simplexml. can register namespace , use xpath expression:
$source = <<<source <?xml version="1.0" encoding="utf-8" ?> <soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <soap:body> <getinfofromsendingresponse xmlns="http://test.test.com/"> <getinfofromsendingresult>{"sendingid":"2468","subject":"test","id":"2468","campaignid":"890","forwardaddress":"test@test.ro","sendingtime":"1/14/2016 8:00:00 am","sendleadstoemail":"0","languageid":"6","leadstestmode":true,"webversionlink":"","language":"fr"}</getinfofromsendingresult> </getinfofromsendingresponse> </soap:body> </soap:envelope> source; $xml = simplexml_load_string($source); $xml->registerxpathnamespace('test', 'http://test.test.com/'); $elements = $xml->xpath('//soap:envelope/soap:body/test:getinfofromsendingresponse/test:getinfofromsendingresult'); $result = json_decode($elements[0], true); print_r($result);
will result in:
array ( [sendingid] => 2468 [subject] => test [id] => 2468 [campaignid] => 890 [forwardaddress] => test@test.ro [sendingtime] => 1/14/2016 8:00:00 [sendleadstoemail] => 0 [languageid] => 6 [leadstestmode] => 1 [webversionlink] => [language] => fr )
Comments
Post a Comment