如何从 PHP 中的以下 SOAP XML 响应中获取 pinBlocked 标记
How to get the pinBlocked tag from the following SOAP XML response in PHP
如何从 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;
您需要使用 xml 作为字符串创建 SimpleXMLElement
的对象,然后使用随机前缀为 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];
如何从 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;
您需要使用 xml 作为字符串创建 SimpleXMLElement
的对象,然后使用随机前缀为 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];