How can I save to a file the xml of the xmlrpc responses received from servers?
Prev | Chapter 12. Frequently Asked Questions | Next

## How can I save to a file the xml of the xmlrpc responses received from servers?

If what you need is to save the responses received from the server as xml, you have two options:

1- use the serialize() method on the response object.

    $resp = $client->send($msg);
    if (!$resp->faultCode())
      $data_to_be_saved = $resp->serialize();

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 <string/>, serialize() will output <string></string>), 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).

2 - set the client object to return the raw xml received instead of the decoded objects:

    $client = new xmlrpc_client($url);
    $client->return_type = 'xml';
    $resp = $client->send($msg);
    if (!$resp->faultCode())
      $data_to_be_saved = $resp->value();

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...

Prev | Up | Next
My client returns "XML-RPC Fault #2: Invalid return payload: enable debugging to examine incoming payload": what should I do? | Home | Can I use the ms windows character set?