如何在PHP中解析我的SOAP XML响应?

时间:2017-01-16 14:58:12

标签: php xml soap

这是我的SOAP响应:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost:8000/soap/index.php?wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns1:testMethodResponse>
            <return xsi:type="xsd:boolean">true</return>
        </ns1:testMethodResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我想退回true。我怎么能这样做?

这就是我正在尝试的:

$xml = simplexml_load_string($res, NULL, NULL, "http://schemas.xmlsoap.org/soap/envelope/");
$ns = $xml->getNamespaces(true);
$soap = $xml->children($ns['SOAP-ENV']);
$res = $soap->Body->children($ns['ns1']);

foreach ($res->TestMethodResponse as $item) {
    echo $item->result.PHP_EOL;
}

0 个答案:

没有答案