在PHP中读取简单的SOAP XML响应

时间:2013-08-02 19:56:25

标签: php xml soap

我找到了一个可靠的工作答案就找不到了。

我也是SOAP新手,但对PHP非常熟悉。

我用CURL发出我的SOAP请求,我的回复如下:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetFeatureResponse xmlns="http://www.supportsite.com/webservices/">
  <GetFeatureResult>**string**</GetFeatureResult>
</GetFeatureResponse>
</soap:Body>
</soap:Envelope>

我需要在没有XML的MySQL数据库中保存 - &gt; GetFeatureResult'字符串'。我尝试的一切都是空白。这就是我现在使用的:

$result = curl_exec($curl);
curl_close ($curl);

$resultXML = simplexml_load_string($result);


$item = $resultXML->GetFeatureResponse->GetFeatureResult;

1 个答案:

答案 0 :(得分:1)

PHP内置soap client。这很容易。只要您将其指向正确的WSDL文件,它就会返回一个可以使用的PHP对象。

编辑:挖出一个我身边的例子......

  $sc = new SoapClient($wsdl, array(
    'location' => "https://$host:$port/path/",
    'login' => $user,
    'password' => $pass
  ));

  //$sc will now contain methods (maybe properties too) defined by the WSDL file
  //Getting the info you need could be as easy as
  $info = $sc->getInfo(array('parameter'=>'value'));