请我开发一个php应用程序,我想知道如何将soap webservice的xml响应转换为字符串或数组或json,我想将webservice返回的值插入到我的数据库中。
这是我的xml respnse:
<env:Envelope xmlns:env="">
<env:Header/>
<env:Body>
<soap:getUserInfoResponse xmlns:soap="">
<getUserInfoResult>
<userInformation>
<detailuserInformationList>
<detailuserInformation>
<Name>Alex</Name>
<alias>Lex</alias>
<age>24</age>
<function>agent</function>
<birthdate>1</birthdate>
<birthmounth>02</birthmounth>
<birthyear>1990</birthyear>
<address>wall street</address>
<civility>mr</civility>
<gender>m</gender>
</detailuserInformation>
</detailuserInformationList>
<lastLogin>14:22</lastLogin>
<userId>A52241</userId>
<cnxTimes>125</cnxTimes>
</userInformation>
<requestTag/>
</getUserInfoResult>
</soap:getUserInfoResponse>
</env:Body>
</env:Envelope>
这是我的PHP代码,调用ws:
$client = new SoapClient('$url', array("trace" => 1, "exception" => 0));
$client->__setLocation('$url');
$response = $client->__soapCall("getUserInfo", array( parameters...);
print htmlspecialchars($client->__getLastResponse());
答案 0 :(得分:0)
答案 1 :(得分:0)
首先,检查代码中$response
的内容:
print htmlspecialchars($response);
顺便说一句,这是正确的方式,或与SoapClient
合作:
$client = new SoapClient($wsdl_url, array('trace' => 1, 'exception' => 0));
$response = $client->getUserInfo( /* parameters */ );
你会在$ response中获得数组。您可以使用$client->__getLastRequest()
和$client->__getLastResponse()
来查看请求和响应XML。