PHP5 SOAP XML转换为Array

时间:2009-12-24 00:02:54

标签: php xml arrays soap nusoap

我目前从SOAP调用返回。

<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
  <soapenv:Body>
    <ns:getMakeResponse xmlns:ns="http://ws.fds.com">
      <ns:return>

        <ResponseCode>000</ResponseCode>  
        <ResponseDescription>No Errors</ResponseDescription>

        <MakeReturn>
          <Make>JEEP</Make>
          <MakeDescription>JEEP</MakeDescription>
        </MakeReturn>

          <MakeReturn>
            <Make>CHRY</Make>
            <MakeDescription>CHRYSLER</MakeDescription>
          </MakeReturn>

      <ns:return>
    </ns:getMakeResponse>
  </soapenv:Body>
</soapenv:Envelope>

如何将其转换为如下所示的数组或类似的数据?

Array
(
    [id] => 1
    [responsecode] => 000
    [responsedescription] => No Errors
    [0] => Array
        (
            [make] => JEEP
            [makedescription] => JEEP
        )
    [1] => Array
        (
            [make] => CHRY
            [makedescription] => CHRYSLER
        )
)

感谢您提供的任何帮助!

2 个答案:

答案 0 :(得分:3)

我找到了这个 http://www.bin-co.com/php/scripts/xml2array/ 这似乎工作得相当好。

答案 1 :(得分:0)

如果您使用本机PHP SoapClient,则输出已被转储到PHP对象...

$client = new SoapClient('...wsAvailability.asmx?wsdl', array('trace' => true, 'exceptions' => 0));
$output = $client->GetWhateverMethod($input);
$xml = $client->__getLastResponse();

查看$ output对象,它应该包含你想要的大部分内容......