Categories
Posts

XML-RPC Types: Dates vs. Strings

The XML-RPC spec outlines 6 types: integer, boolean, string, double, date/time and base64. If you count struct and array as types then we go up to 8 types. The XML-RPC page on Wikipedia has examples of the XML tags for these data types.

One mistake that I’ve seen commonly made (and I’ve done it myself) is to confuse dates and strings. It’s easy to do, most databases for instance treat date input essentially as a string. So it might seem natural that a date would be encoded in XML-RPC as:

[sourcecode lang=”xml”]
<string>19980717T14:08:55</string>
[/sourcecode]

and expect the XML-RPC server to just know that it should be converting that value to a date/time. XML-RPC libraries massage the encoded values based on the XML tag though, so this gets treated as a string. The correct mark up for a date/time value would be:

[sourcecode lang=”xml”]
<datetime.iso8601>19980717T14:08:55</datetime.iso8601>
[/sourcecode]

An XML-RPC library will then put this into a correct date context for that specific programming language.

If you find that a date field in your XML-RPC request isn’t being processed correctly take a look at the raw XML, you may actually be passing it as a string. When a problem comes up spending a minute to verify the XML tag can save you a bigger headache later on.

Leave a Reply

Your email address will not be published. Required fields are marked *