Php Soap,转储结果为XMl FILE?
问题描述:
我得到了一个SOAP(正常的PHP客户端)结果 从我的请求 我想将结果保存为XML文件?但是如何?Php Soap,转储结果为XMl FILE?
$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
答
请问上面的代码不这样做,如果不尝试:
$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";
}
+0
可能是坏的XML是的,谢谢:) – koos
答
$xml->asXML("out.xml");
YES :)谢谢!很简单 !! – koos