Last updated: 08/20/2001
There are actually two components available here. One is the message builder, the other a PHP gateway called xmlrpc-socket that forwards XML-RPC requests to remote servers over the Internet. Together they turn your browser into an XML-RPC client.
Download the library here.
You can read more about the XML-RPC specification here.
These demos use the library to contruct queries for the following XML-RPC services:
First, create a new instance of the XMLRPCMessage object. The syntax is:
var msg = new XMLRPCMessage([string methodName]);
methodName is the name of the method you wish to call on the remote server. This parameter is optional. If left out, the default requested method is
The XMLRPCMessage object has three methods:
|void setMethod(string methodName)||Declares the XML-RPC method you wish to call on the remote server. You only need to use this if you haven't specified a method name when creating the XMLRPCMessage object.|
|string xml()||Returns a string of XML containing the message contents.|
addParameter method and it will be converted to the proper format and value.
The following data types are supported:
|four-byte signed integer||7|
|double-precision signed floating point number||-3.14||The script automagically determines whether a number is an integer or double.|
||Date objects are automatically converted into the ISO8601 format. You cannot pass date strings here; those will remain strings. Instead create a new Date object and use that.|
||You don't have to worry if an Array or Object has a variety of data types as members; the script identifies the data type of each member and includes it in the message.
Both arrays and structs can contain other arrays and structs as members, so it's possible to take a complex Object and describe it in XML by passing it to addParameter (this recursive feature is still being tested, though).
This library does not currently support the base64 data type.
Here is an example of using the XMLRPCMessage object to create a message:
This will create the following XML-RPC message:
Depending upon your implementation, you may need to remove line breaks from, escape or otherwise encode the content of the message before posting it.
The response is also XML-formatted. Once you receive the response string, you can parse it or load it into a DOM object to walk through its elements.
You can see it in action here.
The download is avaliable as a ZIP file (9K) which contains: