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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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