2
0
mirror of https://github.com/ACSPRI/queXS synced 2024-04-02 12:12:16 +00:00
Files
CATI_Tool/include/limesurvey/admin/classes/xmlrpc/doc/ch12s06.html
2011-11-14 04:27:30 +00:00

28 lines
5.8 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>How can I save to a file the xml of the xmlrpc responses received from servers?</title><link rel="stylesheet" href="xmlrpc.css" type="text/css" /><meta name="generator" content="DocBook XSL Stylesheets V1.74.3" /><link rel="home" href="index.html" title="XML-RPC for PHP" /><link rel="up" href="ch12.html" title="Chapter 12. Frequently Asked Questions" /><link rel="prev" href="ch12s05.html" title="My client returns &quot;XML-RPC Fault #2: Invalid return payload: enable debugging to examine incoming payload&quot;: what should I do?" /><link rel="next" href="ch12s07.html" title="Can I use the ms windows character set?" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">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="ch12s05.html">Prev</a> </td><th width="60%" align="center">Chapter 12. Frequently Asked Questions</th><td width="20%" align="right"> <a accesskey="n" href="ch12s07.html">Next</a></td></tr></table><hr /></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id939024"></a>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"><code><span style="color: #000000">
<span style="color: #0000BB">$resp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$client</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">send</span><span style="color: #007700">(</span><span style="color: #0000BB">$msg</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$resp</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">faultCode</span><span style="color: #007700">())<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$data_to_be_saved&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$resp</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">serialize</span><span style="color: #007700">();</span>
</span>
</code></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() will 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"><code><span style="color: #000000">
<span style="color: #0000BB">$client&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">xmlrpc_client</span><span style="color: #007700">(</span><span style="color: #0000BB">$url</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$client</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">return_type&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'xml'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$resp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$client</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">send</span><span style="color: #007700">(</span><span style="color: #0000BB">$msg</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$resp</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">faultCode</span><span style="color: #007700">())<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$data_to_be_saved&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$resp</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">value</span><span style="color: #007700">();</span>
</span>
</code></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="ch12s05.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch12.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch12s07.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">My client returns "XML-RPC Fault #2: Invalid return payload:
enable debugging to examine incoming payload": what should I do? </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Can I use the ms windows character set?</td></tr></table></div></body></html>