duanlinzhen7235
duanlinzhen7235
2013-08-02 19:56

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

已采纳

I have looked for a solid working answer on this can't find one.

I am also New at SOAP, but very familiar with PHP.

I send out my SOAP request with CURL and my response comes back like this:

<?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>

I need to save the ->GetFeatureResult 'string' in a MySQL database without the XML. Everything I try returns blank. Here's what I'm using now:

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

$resultXML = simplexml_load_string($result);


$item = $resultXML->GetFeatureResponse->GetFeatureResult;
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • douyu9012 douyu9012 8年前

    PHP has a built in soap client. It is a LOT easier. As long as you point it to a proper WSDL file, it will return a PHP object ready to use.

    EDIT: Dug up an example I had around...

      $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'));
    
    点赞 评论 复制链接分享

相关推荐