1
<soap:envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:body>
        <acceptleadresponse xmlns="http://tempuri.org/WhiteBox/Lead">
            <acceptleadresult>
                <purchase>false</purchase>
                <rejectreason>Duplicate Lead</rejectreason>
                <tier>0</tier>
                <starttime>2013-09-05T18:15:32.1757337-05:00</starttime>
                <endtime>2013-09-05T18:15:32.2693339-05:00</endtime>
                <redirect>https://www1.paydaymate.com.au/Account/Sorry</redirect>
            </acceptleadresult>
        </acceptleadresponse>
    </soap:body>
</soap:envelope>

我需要获得两个节点,重定向和购买。但所有值也可以(foreach)。我尝试使用命名空间,但实际上我无处可去

$xml = simplexml_load_string($response['response'], NULL, NULL, "http://schemas.xmlsoap.org/soap/envelope/");
//print_r($xml);
$xml->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');

foreach($xml->xpath('//acceptleadresponse') as $header){

    var_export($header->xpath('//acceptleadresult'));

}
4

1 回答 1

0

使用 SimpleXML 执行此操作很简单 :)

$xml = simplexml_load_string($xml);
$xml->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');

$result = $xml->xpath('/soap:envelope/soap:body');
$ar = $result[0];

$result = $ar->acceptleadresponse->acceptleadresult;
print_r($result);

$result 现在将包含:

   SimpleXMLElement Object
   (
       [purchase] => false
       [rejectreason] => Duplicate Lead
       [tier] => 0
       [starttime] => 2013-09-05T18:15:32.1757337-05:00
       [endtime] => 2013-09-05T18:15:32.2693339-05:00
       [redirect] => https://www1.paydaymate.com.au/Account/Sorry
   )
于 2013-09-06T00:31:37.067 回答