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>

リダイレクトと購入の 2 つのノードを取得する必要があります。しかし、すべての値も問題ありません (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 に答える