Jump to content

XML-RPC Server Response Nested Arrays - How to ?struct?


monkeypaw201

Recommended Posts

Hello,

 

I have successfully gotten an XML-RPC server up and running (in CodeIgniter) with a flat array. Now I am trying to enhance it by adding nested arrays, however am running into problems.

 

The output I get from a client is this:

 

Array
(
    [start_time] => 1346601240
    [end_time] => 1346608440
    [data] => Array
) 

 

I believe the problem is that the nested arrays are not using ?struct?, but I can?t be sure. The XML-RPC Server code in question:

 

$data = array();
  foreach($query->result() as $row)
  {
   $data[] = array(
       'valid_time_from' => $row->valid_time_from,
       'valid_time_to' => $row->valid_time_to,
       'hazard_type' => $row->hazard_type,
       'hazard_severity' => $row->hazard_severity,
       'hash' => $row->hash,
       'raw_text' => $row->raw_text,
       );
  }

  $response = array(
       array(
         'start_time' => $parameters['0'],
         'end_time' => $parameters['1'],
         'data' => $data
       ),
     'struct');

  return $this->xmlrpc->send_response($response); 

 

Any suggestions would be much appreciated!

The problem does not reside in the code you've posted, but in the send_response () function. Or rather, its inability to deal with arrays as a part of the response data.

You'll either need to find a method which properly translates the data into XML, supports sending a multi-dimensional array, or rewrite your data aggregation function to flatten it out. I recommend the first.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.