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 
+0

YES :)谢谢!很简单 !! – koos

请问上面的代码不这样做,如果不尝试:

$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"); 

SimpleXMLElement::asXML reference

+0

确认上述不起作用?可能是我得到了几个命名空间的结果? – koos

+0

对不起,不明白。如果SOAP请求成功,则可能需要chec:'is_soap_fault($ result)'。这是关于[is_soap_fault]的手册(http://www.php.net/manual/ru/function.is-soap-fault.php) – J0HN