parse wsdl xml response with namespace into array - code igniter php using nusoap



I have some trouble to parse the xml response from wsdl to array using php. this is the xml respone from wsdl





<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://ift.tt/sVJIaE">
<SOAP-ENV:Body>
<ns0:Header xmlns:ns0="http://ift.tt/1zOlfbf"/>
<ns0:GetCustAccTypeAndBalanceRs xmlns:ns0="http://ift.tt/1xlWDke" xmlns:jms1="http://ift.tt/1sGvYiH">
<ns0:customer_type>2</ns0:customer_type>
<ns0:balance_amt>51300000</ns0:balance_amt>
<ns0:account_status>1</ns0:account_status>
<ns0:account_no>P20111117400700667035625</ns0:account_no>
<ns0:account_type>3</ns0:account_type>
<ns0:customer_id>28650</ns0:customer_id>
</ns0:GetCustAccTypeAndBalanceRs>
<ns0:CommonResponse xmlns:ns0="http://ift.tt/1xlWDkg" xmlns:jms1="http://ift.tt/1sGvYiH">
<ns0:ResponseCode>00</ns0:ResponseCode>
</ns0:CommonResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>



and this is my code in CI PHP





$client = new nusoap_client('http://ift.tt/1zOlh2T', true);
$client->soap_defencoding = 'utf-8';
$client->header = 'Content-Type: ext/xml;charset=UTF-8';
$client->useHTTPPersistentConnection();

if($client->fault)
{
$text = 'Error: '.$client->fault;
print_r($text);die;
}
else{
if ($client->getError())
{
$text = 'Error: '.$client->getError();
print_r($text);die;
}else
{
$ns= array('v2' => 'http://ift.tt/1xlWDke');
$content ='<v2:GetCustAccTypeAndBalanceRq>
<!--Optional:-->
<v2:msisdn>6287877035625</v2:msisdn>
</v2:GetCustAccTypeAndBalanceRq>';
$mesagge = $client->serializeEnvelope($content,false, $ns,'document','literal','');
$result = $client->send($mesagge,'/Services/jmsEP/opGetCustAccTypeAndBalance');
$res = array(
'customer_type' => $respon['GetCustAccTypeAndBalanceRs']['customer_type'],
'balance_amt' => $respon['GetCustAccTypeAndBalanceRs']['balance_amt'],
'account_status' => $respon['GetCustAccTypeAndBalanceRs']['account_status'],
'account_no' => $respon['GetCustAccTypeAndBalanceRs']['account_no'],
'account_type' => $respon['GetCustAccTypeAndBalanceRs']['account_type'],
'customer_id' => $respon['GetCustAccTypeAndBalanceRs']['customer_id'],
'ResponseCode' => $respon['CommonResponse']['ResponseCode'],
'ErrorMessage' => $respon['CommonResponse']['ErrorMessage']
);
$amount = $res['balance_amt'];

return $amount;
}
}



Can someone tell me how to parse the wsdl xml response to array? Thank you so much


No comments:

Post a Comment