views:

126

answers:

2

One thing I've noticed with all the XML-RPC examples out there, including the spec itself, is there is no detailed example of a schema using recursive (param) values. It is hard to understand what should actually be possible within XML-RPC without these illustrations, and I wonder if someone could help me get a better handle on it.

The spec says:

<struct>s can be recursive, any <value> may contain a <struct> or any other type, including an <array>, described below.

<arrays>s can be recursive, any value may contain an <array> or any other type, including a <struct>, described above.

Does that mean it is perfectly legal to do the following:

<?xml version="1.0"?>
<methodCall>
    <methodName>examples.getStateName</methodName>
    <params>
     <param>
      <value>
       <struct>
        <member>
         <name>lowerBound</name>
         <value>
          <struct>
           <member>
            <name>lowerBound</name>
            <value><i4>18</i4></value>
           </member>
           <member>
            <name>upperBound</name>
            <value><i4>139</i4></value>
           </member>
          </struct>
         </value>
        </member>
        <member>
         <name>upperBound</name>
         <value><i4>139</i4></value>
        </member>
       </struct>
      </value>
     </param>
    </params>
</methodCall>

Is it possible to also do this:

<?xml version="1.0"?>
<methodCall>
    <methodName>examples.getStateName</methodName>
    <params>
     <param>
      <value>
       <array>
        <data>
         <value><i4>12</i4></value>
         <value>
          <struct>
           <member>
            <name>lowerBound</name>
            <value>
             <struct>
              <member>
               <name>lowerBound</name>
               <value><i4>18</i4></value>
              </member>
              <member>
               <name>upperBound</name>
               <value><i4>139</i4></value>
              </member>
             </struct>
            </value>
           </member>
           <member>
            <name>upperBound</name>
            <value><i4>139</i4></value>
           </member>
          </struct>
         </value>
         <value><boolean>0</boolean></value>
         <value><i4>-31</i4></value>
        </data>
       </array>
      </value>
     </param>
    </params>
</methodCall>

I'm trying to write an implementation and I need to know all the possibilities, and what to check for when traversing through someone's schema on the server side. With the way the spec reads it appears that you can nest arrays and structs interchangeably, but I wanted to verify that is true. Thanks!

+1  A: 

Yes, I don't see why not. I followed Dave Winer's development of the protocol at the time and have also designed and implemented a cluster computing solution (searching in molecular sequence databases) that used the XML-RPC protocol for communication. It did not use complex structures, but e.g. an item in an array can be any of the 3 (primitive, array, struct).

Peter Mortensen
+1  A: 

Absolutely. I maintain a Perl implementation of XML-RPC, and handling the arbitrary nesting of data (this is more a matter of nesting than it is recursion) was fairly simple.

As you mention that you are working on an implementation of your own (though you should really look to see if your language already has an implementation-- it would be better to contribute to the ongoing development and maintenance of an established project), there is one recent issue I had with nesting and actual, real, recursion that you might want to keep in mind: Assuming your language supports references, be careful that you don't have any cyclic references in your data structures. I just released a new rev of my Perl implementation (http://search.cpan.org/dist/RPC-XML) that fixes an infinite-recursion bug when an array or struct contains cyclical references.

rjray