This repository has been archived on 2024-11-28. You can view files and clone it, but cannot push or open issues or pull requests.
Incam_SGD/thirdparty/xmlrpc-2.2/doc/ch12s07.html

15 lines
3.8 KiB
HTML

<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>7.&nbsp;How can I save to a file the xml of the xmlrpc responses received from servers?</title><link rel="stylesheet" href="html.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.71.1"><link rel="start" href="index.html" title="XML-RPC for PHP"><link rel="up" href="ch12.html" title="Chapter&nbsp;12.&nbsp;Frequently Asked Questions"><link rel="prev" href="ch12s06.html" title="6.&nbsp;My client returns &#34;XML-RPC Fault #2: Invalid return payload: enable debugging to examine incoming payload&#34;: what should I do?"><link rel="next" href="apa.html" title="Appendix&nbsp;A.&nbsp;Integration with the PHP xmlrpc extension"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">7.&nbsp;How can I save to a file the xml of the xmlrpc responses received from servers?</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch12s06.html">Prev</a>&nbsp;</td><th width="60%" align="center">Chapter&nbsp;12.&nbsp;Frequently Asked Questions</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="apa.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e3500"></a>7.&nbsp;How can I save to a file the xml of the xmlrpc responses received from servers?</h2></div></div></div><p>If what you need is to save the responses received from the server as xml, you have two options:</p><p>1- use the serialize() method on the response object.</p><pre class="programlisting">
$resp = $client-&gt;send($msg);
if (!$resp-&gt;faultCode())
$data_to_be_saved = $resp-&gt;serialize();
</pre><p>Note that this will not be 100% accurate, since the xml generated by the response object can be different from the xml received, especially if there is some character set conversion involved, or such (eg. if you receive an empty string tag as &lt;string/&gt;, serialize() will output &lt;string&gt;&lt;/string&gt;), or if the server sent back as response something invalid (in which case the xml generated client side using serialize() wil correspond to the error response generated internally by the lib).</p><p>2 - set the client object to return the raw xml received instead of the decoded objects:</p><pre class="programlisting">
$client = new xmlrpc_client($url);
$client-&gt;return_type = 'xml';
$resp = $client-&gt;send($msg);
if (!$resp-&gt;faultCode())
$data_to_be_saved = $resp-&gt;value();
</pre><p>Note that using this method the xml response response will not be parsed at all by the library, only the http communication protocol will be checked. This means that xmlrpc responses sent by the server that would have generated an error response on the client (eg. malformed xml, responses that have faultcode set, etc...) now will not be flagged as invalid, and you might end up saving not valid xml but random junk...</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch12s06.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="ch12.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="apa.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">6.&nbsp;My client returns "XML-RPC Fault #2: Invalid return payload: enable debugging to examine incoming payload": what should I do?&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;Appendix&nbsp;A.&nbsp;Integration with the PHP xmlrpc extension</td></tr></table></div></body></html>