Tub 'o' Dogs

55. Using XML-RPC libraries to share complex variables

WDDX - an open standard for serialising complex variables into a portable XML format - was a good idea that never took off. We were talking about this at work when I realised that XML-RPC, for which libraries are built in or easily available to most modern languages, requires exactly this functionality. Some implementations might need a little work to strip out or mock up the unwanted transport layer, but in most cases you only need a few lines of code to switch between complex variables and a portable XML string.

Here are examples in Python, Perl and Ruby - run them piped together like this:

./xmlrpc.py | ./xmlrpc.pl | ./xmlrpc.rb

Could XML-RPC offer the marshalling standard that REST is looking for?

Python:
import xmlrpclib

orwell={'1': 'All languages are equal'}
print xmlrpclib.dumps(tuple([orwell]),methodresponse=1)
Perl (needs SOAP-Lite):
use XMLRPC::Lite;

undef $/; $package = <>;
$data = XMLRPC::Deserializer->deserialize($package);
@args = $data->valueof("params");
%orwell=%{$args[0][0]};
$orwell{'2'}='But some languages are more equal than others';
print XMLRPC::Serializer->envelope('response', 'null',\%orwell);
Ruby:
require "xmlrpc/marshal"

depacket = XMLRPC::Marshal.load(STDIN.gets)
for key in depacket.keys()
        puts depacket[key]
end

Update: there's prior art here and here.