Php Soap,将结果转储为 XMl 文件?

发布于 2024-11-30 13:15:43 字数 270 浏览 1 评论 0原文

我得到了 SOAP(普通 php 客户端)结果 根据我的要求 我想将结果保存为 XML 文件?但如何呢?

   $result = $client->__soapCall('MYwebServices',array($params));

    $xml = simplexml_load_string($result);

    $fp = fopen("out.xml","w");
    fwrite($fp,$xml);
    fclose($fp);

I got a SOAP (normal php client) Result
from my request
I want to save the result as a XML file ? But how ?

   $result = $client->__soapCall('MYwebServices',array($params));

    $xml = simplexml_load_string($result);

    $fp = fopen("out.xml","w");
    fwrite($fp,$xml);
    fclose($fp);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

巷子口的你 2024-12-07 13:15:43

如果你想获取Web服务返回的XML,你应该使用 SoapClient::__getLastResponse()(以及 trace 选项)。

$client = new SoapClient(..., array('trace' => 1));

// Do your __soapCall here

$xml = $client->__getLastResponse();

// Work with the XML string here

If you want to get the XML returned by the web service, you should use SoapClient::__getLastResponse() (along with the trace option).

$client = new SoapClient(..., array('trace' => 1));

// Do your __soapCall here

$xml = $client->__getLastResponse();

// Work with the XML string here
維他命╮ 2024-12-07 13:15:43
$xml->asXML("out.xml");

SimpleXMLElement::asXML 参考

$xml->asXML("out.xml");

SimpleXMLElement::asXML reference

掩饰不了的爱 2024-12-07 13:15:43

上面的代码是否不这样做,如果不尝试:

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

Does the code above not do it, if not try:

$result = $client->__soapCall('MYwebServices',array($params));

    $xml = new DOMDocument();
$xml->load($result);
$xml->save("out.xml");

This might be broken if the return is not xml or the xml is improperly formatted, in which case try this:

$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";
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文