2013-08-27 22:04
浏览 81

使用PHP / xpath解析SOAP响应 - 不能超过一个节点

I've tried to read other tutorials & SO responses on this but I just can't seem to make it work :/

I'm able to make the SOAP request and get a response but I can't seem to parse the response.

$result = $client->GetAllAttributes($params);

And the resulting response xml is:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <GetAllAttributesResponse xmlns="http://connect2.askadmissions.net/webservices/">
       <ErrorMessage />
            <level />
            <mappingname><![CDATA[Extra-Curricular Interest]]></mappingname>
            <validationexp />
           <attribute> (same as above, several of these are returned</attribute>

I've tried

$xml = simplexml_load_string($client->__getLastResponse());

But it just prints "SimpleXMLElement Object ( ) "

I've tried

$responseXML = $client->__getLastResponse();
        $xml = simplexml_load_string($responseXML);
        $xml->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');
        $xml->registerXPathNamespace('hob', 'http://connect2.askadmissions.net/webservices/');
        $item = $xml->xpath('//hob:GetAllAttributesResult');

and I get an array

[0] => SimpleXMLElement Object
        [0] => <result><code>1</code><ErrorMessage /><returndata><attributes><attribute>    <type>attribute</type><level />

etc. (array is very long)

My problem comes when I try to step further into the tree. If I do

$item = $xml->xpath('//hob:GetAllAttributesResult/hob:result');


$item = $xml->xpath('//hob:GetAllAttributesResult/hob:code');

I end up with an empty array.

How do I step further into the tree?

Thank you very much for any help.

1条回答 默认 最新

相关推荐 更多相似问题