Matt Goodall: CouchDB and XML

Everyone knows by now that CouchDB is a JSON document store, right? What’s not quite so obvious is that it handles XML very nicely too via E4X. Strictly speaking, it’s the Mozilla Spidermonkey JavaScript engine that provides the E4X support but that’s CouchDB’s default view server.
I’m calling out to a 3rd party SOAP service and the result is returned as an XML string (don’t blame me for that, it’s what their WSDL file says). I’ve been tossing that result into a CouchDB doc – it’s so easy, you might as well – in case I needed to refer to it later.
That time has come as I now need to be a bit more selective about how I handle the result. So, I fired up CouchDB’s Futon and wrote a view that emitted bits of the JSON together with the interesting parts of the XML blob. Now I have a simple view of the data without all the XML “noise”. Very nice :).
What’s best about this is that using CouchDB, XML and E4X together is trivial and E4X is compact and quick to learn.

Comments are closed.