I haven’t seen this suggested anywhere so I thought I would just put this out there and let the lazyweb inform me who invented this first. :-)
Cool frameworks like Rails, Django , and Plone provide a nice little HTML framework to show you validation errors on screen. They pin-point exactly where you goofed. This is nice.
Here’s an example using Django :

Now let’s say I’m writing a RESTful web services API. Let’s say I’m implementing the Atom Publishing Protocol or maybe a clone of the 37Signals’ Backpack API.
From what I can tell from these protocols, there is no guidance on how to provide “fine grained” detail on exactly where the error is. If I’m submitting a 10 item expense report, how do can I tell the user that the project code for expense item #8 is invalid and have a computer be able to interpret that and highlight it in the UI. The UI could be an excel spreadsheet or even a hacked version of a TiddlyWiki. The point is I’m trying to decouple the user interface from the server interface.
Here’s my idea… Add the error message as an attribute to the item that failed the validation.
For example, here’s an expense report that I’ll submit to the server:

The server would send the data back to the user, modified with the error text “built-in”:

By setting the error message as an attribute of the element that failed a validation, my UI code can parse the XML and will know exactly which element to highlight on screen with the error.
Of course, this assumes that the source document itself was valid XML. Anyway, that’s my idea. Thanks for reading.



This would require the error attribute to be included in the schema or DTD of every validatable XML file sent back. Also, the message cannot contain rich information such as links. It might be better to define an error namespace and allow some subset of XHTML or similar markup to be used in the error message, like:
<expense-item xmlns:error=”http://www.jrandolph.com/xmlns/error/1,0″>
<project><error:report>Project not a <a href=”valid_codes.html”>valid code</a></error>
…
Link | November 11th, 2005 at 6:35 pm
Or just don’t use a RESTful API. Nobody wants to bind to it anyway :)
Link | November 13th, 2005 at 8:19 pm