我得到了一个SOAP(普通php客户端)结果根据我的请求我想将结果保存为XML文件吗?但是怎么做呢?
$result = $client->__soapCall('MYwebServices',array($params));
$xml = simplexml_load_string($result);
$fp = fopen("out.xml","w");
fwrite($fp,$xml);
fclose($fp);
如果您想获得web服务返回的XML,您应该使用SoapClient::__getLastResponse()
(以及trace
选项)。
$client = new SoapClient(..., array('trace' => 1));
// Do your __soapCall here
$xml = $client->__getLastResponse();
// Work with the XML string here
$xml->asXML("out.xml");
SimpleXMLElement::asXML
参考
上面的代码不这样做,如果不尝试:
$result = $client->__soapCall('MYwebServices',array($params));
$xml = new DOMDocument();
$xml->load($result);
$xml->save("out.xml");
如果返回的不是xml或xml格式不正确,则可能会被破坏,在这种情况下,请尝试以下操作:
$result = $client->__soapCall('MYwebServices',array($params));
libxml_use_internal_errors(true);//load if improperly formatted
$xml = new DOMDocument();
if ($xml->load($result))
{
$xml->save("out.xml");
}
else {
echo "The return data was not xml";
}