A Wolfram Mathematica xmlRPC package

The xmlRPC package allows to transparently access an XML-RPC server directly within Wolfram Mathematica. The package is described in the paper Implementing an XML-RPC client in Mathematica, authored by myself and presented at the IMS 2006 conference.

Prerequisites

The package requires a working installation of Wolfram Mathematica.

Install instructions

The software is available on GitHub, and is installed as follows.

  1. Clone the xmlRPC repository locally.
  2. Copy the file xmlRPC.m according to the following table, depending on the operating system you use and your preference for a user-based or a system-wide installation.
    OS User-based installation System-wide installation
    Mac OS X ~/Library/Mathematica/Applications /Library/Mathematica/Applications
    Linux ~/.Mathematica/Applications R/AddOns/Applications
    Windows ~/Applications Data/Mathematica/Applications R/AddOns/Applications
    In the table ~ denotes the user's home directory in Mac OS X and Linux and the user's directory inside Documents and Settings in Windows, while R denotes the Mathematica root directory.
    Note If you like the non-standard way, saving the package file in any directory contained in Mathematica's $Path variable will also work.
  3. Read the user manual notebook xmlRPC-usage.nb.

Using the package

The package is loaded as follows

In[1]:= <<xmlRPC`

The package implements the functions xmlRPCInit and xmlRPC, allowing respectively to connect to a specific XML-RPC server and to remotely invoke a given procedure.

Consider for instance the NEOS server allowing to remotely solve constrained optimization problems. This server is accessible in several ways, including an XML-RPC server at the address neos-1.chtc.wisc.edu and running on the port 3332. In order to remotely invoke the functions of this server, it is necessary to connect to it once through xmlRPCInit:

In[2]:= xmlRPCInit["neos-1.chtc.wisc.edu", 3332];

This function accepts two parameters, namely the server address and port; the value returned does not need to be retained. After the connection has been established, xmlRPC allows to actually execute a procedure. For instance,

In[3]:= xmlRPC["version", {}]
Out[3]= "neos version 5 (Madison)"

The function xmlRPC accepts two parameters: the first one is a string containing the procedure name, while the second is a list encoding the arguments passed to the procedure. This list should always be specified, even when the invoked procedure accepts no parameters, such as in previous example. In the latter case the second argument of xmlRPC will be an empty list. Each argument is in turn encoded into a two-values list, containing respectively a string describing the argument type and a value for the argument. The following table lists the currently accepted argument types.

Type Description Example
i4, int Integer value {"int", 42}
double Floating point value {"double", 3.14152}
string String value {"string", "The quick brown fox jumps over the lazy dog"}
dateTime.iso8601 Date and time expressed in the ISO8601 format {"dateTime.iso8601", "2012-12-20T12:00:00"}

The value returned by xmlRPC is automatically converted into the more appropriate Mathematica type. The xmlRPC package supports all return types in the XML-RPC protocol, detailed in the following table.

XML-RPC Type Description Returned Mathematica type
i4, int Integer value Integer
double Floating point value Real
boolean Boolean value True or False
string String value String
dateTime.iso8601 Date and time expressed in the ISO8601 format List of values using the format of ToDate
base64 Binary expressed through the base64 encoding String
array Array of data List
struct XML structure XMLObject

License

xmlRPC is licensed uder the LGPL license.