简体   繁体   English

PHP5 SOAP XML转换为数组

[英]PHP5 SOAP XML into Array

I currently have a return from a SOAP call. 我目前有一个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>

How can I turn this into an array like below, or something similar? 我如何将其转换为如下所示的数组或类似的东西?

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

Thanks for any help provided! 感谢您提供的任何帮助!

我发现这个http://www.bin-co.com/php/scripts/xml2array/看起来效果不错。

If your using the native PHP SoapClient the output already gets dumped into a PHP Object... 如果您使用本地PHP SoapClient,则输出已被转储到PHP对象中。

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

Look at the $output object, it should have most of what you want... 看一下$ output对象,它应该具有您想要的大部分内容...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM