2012-10-07 67 views
0

我一直在嘗試使用simplexml檢索ResponseCode,ResponseDescription,金額和CardNumber,但它一直返回一個空字符串。檢索ResponseCode,ResponseDescription,金額和卡號

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
    <s:Body> 
    <GetTransactionDataResponse xmlns="http://services.interswitchng.com/"> 
    <GetTransactionDataResult xmlns:a="http://schemas.datacontract.org/2004/07/WebPAY.Core.ServiceFramework.Contract" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> 
    <ResponseCode xmlns="http://schemas.datacontract.org/2004/07/TechQuest.Framework.ServiceFramework.Contract">61</ResponseCode><ResponseDescription xmlns="http://schemas.datacontract.org/2004/07/TechQuest.Framework.ServiceFramework.Contract">Exceeds Withdrawal Limit</ResponseDescription> 
    <a:Amount>10000000</a:Amount> 
    <a:CardNumber>3386</a:CardNumber> 
    <a:LeadBankCbnCode i:nil="true"/><a:LeadBankName i:nil="true"/> 
    <a:MerchantReference i:nil="true"/><a:PaymentReference i:nil="true"/> 
    <a:RetrievalReferenceNumber i:nil="true"/><a:SplitAccounts/> 
    <a:TransactionDate>0001-01-01T00:00:00</a:TransactionDate> 
    </GetTransactionDataResult> 
    </GetTransactionDataResponse> 
    </s:Body> 
    </s:Envelope> 
+1

考慮使用解析XML和東西張貼的代碼你,你已經嘗試這樣遠遠得到它的工作。 – iamkrillin

回答

0

如果你指的是SOAP響應我將採取Nusoap一看,是一個PHP Web服務庫來處理所有的轉換和XML使得它非常容易使用web服務。

我已經使用它了很多我自己。

0

如果您使用的是Interswitch支付系統,則應該得到此信息。使用SoapClient相反,但如果你仍然需要解析這則:

$sxe = new SimpleXmlElement($xml); 
$sxe->registerXPathNamespace('s', 'http://schemas.xmlsoap.org/soap/envelope/'); 
$sxe->registerXPathNamespace('a', 'http://schemas.datacontract.org/2004/07/WebPAY.Core.ServiceFramework.Contract'); 
$sxe->registerXPathNamespace('i', 'http://www.w3.org/2001/XMLSchema-instance'); 

$list = array(); 
$list['code'] = (string) $sxe->children("s", true)->Body->children()->GetTransactionDataResponse->GetTransactionDataResult->ResponseCode; 
$list['desciption'] = (string) $sxe->children("s", true)->Body->children()->GetTransactionDataResponse->GetTransactionDataResult->ResponseDescription; 
$list['amount'] = (string) $sxe->xpath('//a:Amount'); 
$list['amount'] = (string) $list['amount'][0]; 
$list['card'] = $sxe->xpath('//a:CardNumber'); 
$list['card'] = (string) $list['card'][0]; 

echo "<pre>"; 
print_r($list); 

輸出

Array 
(
    [code] => 61 
    [desciption] => Exceeds Withdrawal Limit 
    [amount] => A 
    [card] => 3386 
) 

See Live Demo