問題描述
我想轉換一個soap xml 響應并將其存儲在數據庫中.這是我擁有的 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>
我從服務器得到這個soap響應.我想將其轉換為數組并將其存儲在數據庫中.我該怎么辦?我知道答案可能很簡單,但是嘿,我是新手 :D
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.
謝謝你的期待.
問候
推薦答案
最好的解決方案是使用 PHP 的 SoapClient 類進行調用,該類將返回一個對象,然后將該對象轉換為數組,如下所示:
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.
這篇關于PHP - 在 PHP 中將 XML 轉換為數組 - 在 php 中解析一個 soap xml 并將其存儲在數據庫中的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!