php - SOAP envelop parsing with all XMLNS - not working on Magento -
i have tried , tried , have been unable come solution. issue this: have soap envelop response follows...
<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:header> <soapenv:body> <mcu:prescreenusereligibilityresponse xmlns:mcu="http://www.ups.com/xmlschema/xoltws/mcusereligibility/v1.0"> <common:response xmlns:common="http://www.ups.com/xmlschema/xoltws/common/v1.0"> <common:responsestatus> <common:code>1</common:code> <common:description>success</common:description> </common:responsestatus> </common:response> <mcu:eligibilitystatuscode>3</mcu:eligibilitystatuscode> </mcu:prescreenusereligibilityresponse> </soapenv:body> </soapenv:header> </soapenv:envelope>
i access elements on mac:
$ns=array(); $xml=new simplexmlelement($string); foreach($xml->getnamespaces(true) $key=>$url){ $xml->registerxpathnamespace($key, $url); $ns[]=strval($url); } print_r(strval($xml->children($ns[0])->header->body->children($ns[1])->prescreenusereligibilityresponse->eligibilitystatuscode));
using same method on separate linux instance error on print_r
line, saying last child cannot null. have confirmed values correct. have tried using $xml->xpath('//mcu:eligibilitystatuscode')
no success.
i'm stuck -_-
i used alternative. domdocument()
i noticed after printing out different object nodes screen, capitalization in xml string different. tried comparing namespaces proper capitalization , still had no success using simplexml.
$doc = new domdocument(); $doc->loadxml($result); if($doc){ foreach($doc->getelementsbytagnamens('*', '*') $element){ if($element->tagname=='mcu:eligibilitystatuscode'){ if($element->nodevalue==0){ return true; } else{ return false; } } } return false; } else{ return false; }
above working code, result xml returned soap request. code cycles through each node in xml response. in turn displays on block on magento front end.
Comments
Post a Comment