need help with XML-RPC server side (or, creating variables on the run...)
Andre Garzia
soapdog at mac.com
Tue Jul 6 23:00:42 EDT 2004
Hi Folks,
I am finishing a XML-RPC server side implementation and stumbled in a
problem. For those that are not familiar with XML-RPC let me explain it
briefly and also note why it is so important to us. XML-RPC Stands for
XML Remote Procedure Call. I hope that everyone here is familiar with
XML, XML is a kind of text document with special tags one can use to
represent arbitrary data, it feels similar to HTML but it's general
purpose, an simple example might be:
<employeeList>
<employee id="01">Andre Garzia</employee>
<employee id="02">Mr Murphy</employee>
</employeeList>
One trying to understand XML better should read the wonderfull tutorial
by Sarah at http://www.troz.net/Rev/#XMLdemo1 this will teach the
basics of XML and why it's good for us. Now lets get back to the RPC
part of XML-RPC. When we code in transcript, we write handlers and
functions, our programs call this handlers and functions to work. What
a RPC system does is to make possible that one program can call a
handler/function of another program across a network (or even on the
same machine). This way we can have a engine on the server and a client
on the local machine and the client would call the needed functions on
the server. A real world demo of this is the Blogger API that drives
the weblogs hosted on Blogger.com (which is now a google company). You
can use the HTML interface to manage your blog or use a custom client
running on your desktop. Either way, when you post a new entry to your
weblog, the client (HTML interface or custom) sends a remote procedure
call to the server, this call is called Blogger.newPost with your login
and the entry as parameters, then the entry is added to your blog, it's
elegant and simple and one of the reasons behind the blog revolution.
The protocol that drives this is XML-RPC, that's the lingua franca
spoken between the server and the clients.
to use XML-RPC one assemble the call as a XML and POST it to the
server, the server then answers the result. It's that simple. To see
the spec of XML-RPC just point your browser to http://www.xmlrpc.com an
simple example of XML-RPC call is this:
<?xml version="1.0"?>
<methodCall>
<methodName>examples.getStateName</methodName>
<params>
<param>
<value><i4>41</i4></value>
</param>
</params>
</methodCall>
See the handler to be called on the server is identified as
examples.getStateName and the only parameter is a integer, 41.
What I am implementing is the server side of this, the part that takes
the XML and feeds it to revolution so that you could do this:
<?xml version="1.0"?>
<methodCall>
<methodName>myStack.add</methodName>
<params>
<param>
<value><i4>1</i4></value>
<value><i4>1</i4></value>
</param>
</params>
</methodCall>
and your result would be 2. Remember, that would be executed on a
remote machine and the result sent to your app. Thats as easy as a
distributed app can be. Now the problem. What I am doing is, parse the
XML to extract the handler to be called then start parsing the
parameters, there can be any number of params in a call, there's no way
to predict it. So how do I store this parameters? I want the the above
XML call to be translated to the following code:
send "add 1 1" to stack "myStack"
with string is easy, we can just append them to the message we will
call, but XML-RPC calls can contain arrays and even dictionaries (keyed
arrays) as parameters, I need a way to create variables on the fly
while parsing and then assemble them all in a line to use "send"
function. I thought about using an array, but arrays can't contain
arrays, so if the XML contains an array then my solution folds...
I could use a data structure common to CS students, the Stack, where I
would push elements into it as I go parsing the XML, then when
assembling the "send" line I could pull the elements from the stack and
do it, my problem is, I am not succeeding in implementing a Stack Data
Structure that can contain arrays... if someone here can help or can
think in another way to implement a way to store an arbitrary number of
parameters please tell me. I want to be ready with this before the
summit... It would be a great addition to demo XML-RPC server side
there...
Cheers
Andre
--
Andre Alves Garzia 2004
Soap Dog Studios - BRAZIL
http://studio.soapdog.org
More information about the use-livecode
mailing list