如何从SOAP XML响应中获取特定节点值

时间:2014-10-14 08:56:10

标签: php soap xpath xml-parsing xml-namespaces

我想获取以下节点的值:

ResponseMessage,响应结果和VelocitiHotLeadID

来自 SOAP XML 响应:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<SubmitHotLeadDetailsResponse xmlns="http://tempuri.org/">
<SubmitHotLeadDetailsResult xmlns:a="http://schemas.datacontract.org/2004/07/Velociti.Webservice.VelocitiHotLead" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <a:ResponseMessage>1:VendorID Does Not Exist 2:IDNumber is invalid.</a:ResponseMessage>
    <a:ResponseResult>false</a:ResponseResult>
    <a:VelocitiHotLeadID>0</a:VelocitiHotLeadID>
</SubmitHotLeadDetailsResult>
</SubmitHotLeadDetailsResponse>
</s:Body>
</s:Envelope>

我尝试使用此代码,但它不起作用:

$xml = simplexml_load_string($result, NULL, NULL, "http://schemas.xmlsoap.org/soap/envelope/");
$xml->registerXPathNamespace('s', 'http://schemas.xmlsoap.org/soap/envelope/');
$xml->registerXPathNamespace('a', 'http://schemas.datacontract.org/2004/07/Velociti.Webservice.VelocitiHotLead');
$xml->registerXPathNamespace('i', 'http://www.w3.org/2001/XMLSchema-instance');
foreach($xml->xpath('//a:ResponseMessage') as $response)
{
   echo $response;
}

0 个答案:

没有答案