Archive for August 2008

Pesterfish

August 28, 2008

In my research for what data serialisation models to use to represent our repository data, I was hunting down some XML to JSON conversions. For the past few months I have been hell-bent on using JSON as the representations, because it is far more useful to me than chunks of XML, and closer to the nature of the data being represented. As Steve Yegge says:
“XML is better if you have more text and fewer tags. And JSON is better if you have more tags and less text”.

The problem is however that almost all the tools out there in Fedora-Commons land are biased towards XML, and have (almost) never heard of JSON. So if I only have some basic Dublic Core and a gob of JSON in my objects, that is not going to help very much. The other extreme, and undoubtedly “The Right Way To Do It” is to have a lovely shiny Content Model and define everything in an ontology and RDF and then my brain melts. And we want to migrate our repository sooner rather than later and don’t have the time to remain in la-la land designing around our navels forever.

So now I am swinging back the other way and have decided to store the data in the objects as simple stupid XML with a smattering of tags, and at least have some XSLT disseminators to provide more buzzword compliant FOAF, Bibliontology, OAI-ORE etc. And JSON. Via XSLT. Which brings me to http://code.google.com/p/xml2json-xslt/ which pointed at http://badgerfish.ning.com/ and finally to pesterfish:

Jacob Smullyan wrote a related Python model, pesterfish, which he describes as: “a quick Python module which is uses the same xml object model as the dominant xml module in the Python world, elementtree; Some elementtree implementation (there are several) and simplejson are required. BTW, elementtree stores namespaces in Clark notation: {http://www.w3.org/1999/xhtml}br and so does this.”. pesterfish also lets you round trip XML through it without any data loss.

I like the ElementTree API. Lots. It is very elegant and a joy to work with, especially if you have ever had to use any other XML APIs like DOM or SAX that makes you want to gnaw your own arm to the bone out of frustration. So the chance of having an ElementTree-like way of consuming XML in Javascript expecially appeals to me. (well until http://en.wikipedia.org/wiki/E4X E4X is widely supported)

And so, with this long-winded preamble I would like to present pesterfish on AppEngine:

http://epoz.appspot.com/pesterfish/

You can POST an XML file to it, and it will return the pesterfish application/json.

Or you can call it with a URL for the XML file specified in the ‘in=’ parameter, like this.

http://epoz.appspot.com/pesterfish/?in=http://www.w3schools.com/XML/note.xml

It turns this XML:

<note>

	<to>Tove</to>

	<from>Jani</from>

	<heading>Reminder</heading>

	<body>Don't forget me this weekend!</body>

</note>

Into this JSON:

{"text": "\n\t", "tag": "note", "children":
 [{"text": "Tove", "tail": "\n\t", "tag": "to"},
 {"text": "Jani", "tail": "\n\t", "tag": "from"},
 {"text": "Reminder", "tail": "\n\t", "tag": "heading"},
 {"text": "Don't forget me this weekend!
", "tail": "\n", "tag": "body"}]}

And it supports JSONP:

http://epoz.appspot.com/pesterfish/?in=http://www.w3schools.com/XML/note.xml&callback=some_callback

Thanks Jacob!

Quotes from Jeremy Clarkson, writer and presenter of Top Gear

August 20, 2008

A friend mailed me these quotes this morning, and I twittered about one of them. It was a completely silly one about librarians, which jumped out at me because I happen to also work in a library. The quote was too long and in splitting it to fit into tweets, I inadvertently reversed the order of the statements.

Ah, the danger of languages and meaning.

On another level it made me smile. I have been to events where librarians were involved that would make Mr Clarksons eyebrows raise. The public image of librarians is very much removed from the reality.

Here is the complete list mailed to me, for reference purposes:

‘I’m sorry, but having a DB9 on the drive and not driving it is a bit like having Keira Knightley in your bed and sleeping on the couch.’

‘… the last time someone was as wrong as you, was when a politician stepped off an aeroplane in 1939 waving a piece of paper in the air saying
there will be no war with Germany ’

Illustrating the lack of power of a Boxster: ‘It couldn’t pull a greased stick out of a pig’s bottom’

On the Vauxhall Vectra VXR: ‘there is a word to describe this car: it begins with ‘s’ and ends with ‘t’ and it isn’t soot

‘The Suzuki Wagon R should be avoided like unprotected sex with an Ethiopian transvestite’

‘The air conditioning in a Lambos used to be an asthmatic sitting in the dashboard blowing at you through a straw.’

‘Koenigsegg are saying that the CCX is more comfortable. More comfortable than what… BEING STABBED?’

‘This is the Renault Espace, probably the best of the people carriers. Not that that’s much to shout about. That’s like saying ‘Ooh good I’ve got
syphilis, the BEST of the sexually transmitted diseases.”

‘I don’t understand bus lanes. Why do poor people have to get to places quicker than I do?’

Clarkson’s highway code on cyclists: ‘Trespassers in the motorcars domain, they do not pay road tax and therefore have no right to be on the road,
some of them even believe they are going fast enough to not be an obstruction. Run them down to prove them wrong.’

‘ Britain ‘s nuclear submarines have been deemed unsafe…probably because they don’t have wheel-chair access.’

‘Now we get quite a lot of complaints that we don’t feature enough affordable cars on the show…….so we’ll kick off tonight with the cheapest Ferrari of them all!’

On the Lotus Elise: ‘This car is more fun than the entire French air force crashing into a firework factory.’

‘Sure it’s quiet, for a diesel. But that’s like being well-behaved….for a murderer.’

‘I don’t often agree with the RSPCA as I believe it is an animal’s duty to be on my plate at supper time.’

‘There are footballers wives that would be happy with this quality of stitching… on their face.’

‘Much more of a hoot to drive than you might imagine. Think of it if you like, as a librarian with a G-string under her tweed pants. I do, and it helps.’

‘You cannot have this car with a diesel. Its like saying, I won’t go to Stringfellows tonight, I’ll get my mum to give me a lapdance, she’s a woman!’

‘Tonight, the new Viper, which is the American equivalent of a sportscar… in the same way, I guess, that George Bush is the equivalent of a President.’

On the Porsche Cayenne: ‘Honestly, I have seen more attractive gangrenous wounds than this. It has the sex appeal of a camel with gingivitis.’

Statelessness, Buddha-nature, purely descriptive markup

August 18, 2008

A great quote by Tim Bray:

And I think there’s a lesson here: that statelessness, like many other good things (Buddha-nature, purely descriptive markup) is an Aristotelian virtue; unattainable in an absolute sense, but rewarded to the extent you can practice it.

Posthing it here because it struck me as a great quote which I would love to remember, but it goes way past the 160 chars to Twitter it. The most recent flare-up in the REST debate which he refers to in that post has been very enjoyable to see now that many more people have started to think that the WS-* stuff is bunk. Good to not jump in the next bandwagon without questions.