如何從 PHP 中的以下 SOAP XML 回應中獲取 pinBlocked 標記
這是我的 SOAP XML 回應:
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><ReadCardStatusResponse xmlns="http://theapi.com"><result>1</result><errorMessage>ok</errorMessage><status><terminalID>123456789</terminalID><profileNumber>123456789</profileNumber><reference>37292141</reference><valid>true</valid><pinBlocked>true</pinBlocked><activated>true</activated><retired>false</retired><loaded>true</loaded><redeemed>true</redeemed><empty>true</empty><cancelled>false</cancelled><stopped>true</stopped><lost>false</lost><stolen>false</stolen><expired>false</expired><transactionID>blahblah</transactionID><transactionDate>2004-10-28T08:54:27</transactionDate><checksum>blahblah</checksum><resultCode>1</resultCode><resultText>ok</resultText></status></ReadCardStatusResponse></soap:Body></soap:Envelope>
回應保存在 $result 中
我試過
$result->pinBlocked;
uj5u.com熱心網友回復:
您需要SimpleXMLElement使用您的 xml 作為字串創建物件,然后注冊命名空間以http://theapi.com使用隨機前綴(在本例中我使用的是a),然后使用xpath之前注冊的前綴獲取您的元素。
$xml = new SimpleXMLElement($result);
$xml->registerXPathNamespace('a', 'http://theapi.com');
echo (bool)$xml->xpath('//a:pinBlocked')[0];
對于 PHP 5.3.3,請使用:
$xml = new SimpleXMLElement($result);
$xml->registerXPathNamespace('a', 'http://theapi.com');
$item = $xml->xpath('//a:pinBlocked');
echo $item[0];
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/339833.html
下一篇:我需要回傳JSON作為美容表樣式
