duanjing4623 2011-09-22 11:52
浏览 187
已采纳

PHP - 在PHP中将XML转换为数组 - 在php中解析soap xml并将其存储在数据库中

I want to convert a soap xml response and store it in a database. Here is the XML that I have.

<ENV:Envelope xmlns:ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://example.com/soap/example">
   <ENV:Body>
      <ns1:GetCentresResponse>
         <ExampleCentre>
            <ns1:Cent>
               <ID>200</ID>
               <Name>example2</Name>
               <Code>ex2</Code>
               <Email>example2@example2.com</Email>
               <Address1>example2, example2 </Address1>
               <Address2>example2, example2 </Address2>
               <City>example2</City>
               <PostCode>111111</PostCode>
               <Telephone>1111111111</Telephone>
               <Location>11.11,-11.11</Location>
               <URL>/example2/exam2/ex2</URL>
            </ns1:Cent>
         </ExampleCentre>
      </ns1:GetCentresResponse>
   </ENV:Body>
</ENV:Envelope>

I get this soap response from the server. I want to convert this to a array and store it in database. What should I do? I know the answer might be pretty straight forward, but hey, am a newbie :D

Would really appreciate any help I get.

Thank you in anticipation.

Regards

  • 写回答

3条回答 默认 最新

  • dpsu84620 2011-09-22 12:08
    关注

    The best solution would be to use PHP's SoapClient class to do the call which will return you an object and then converting this object to an array, like so:

    <?php
    $client = new SoapClient("http://localhost/code/soap.wsdl");
    
    // Soap call with HelloWorld() method
    $something =  $client->HelloWorld(array('option1' => 'attribute1'));
    
    // Convert object to array
    $array = (array)$something;
    
    ?>
    

    Which you can then store in the database.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集