Notalib/LYT — Issue #17: getContentList's $-string-separator-hack
Author: Flambino
Created: 2011-12-01 07:28:37+00:00
State: open
Labels: server-side

When retrieving a user's bookshelf (i.e. calling `/getContentList` for `issued` items), the response XML contains a hack in order to include both a book's title and author, by using "$" as a separator.

Specifically, a `contentItem` node looks like this

Book title$Author name

For one, this is probably at odds with the Daisy specification. It's at least against the spirit of it, I believe.

Second, it's inflexible. If more data needs to be sent, the client-side would need to be updated to "know" what data the different sections of the string contain.

But most importantly, it's fragile. If a book's title – or for that matter the author's name – contains a "$", it becomes impossible to parse the text correctly.
And it's not a far-fetched risk. Imagine an eponymous autobiography by the singer Ke$ha, for instance: `Ke$ha$Ke$ha` (I know, it's a terrible thought, and not just for technical reasons). There's just no good way to parse a string like that.

## Possible solutions

A better solution would be to include an attribute node in a different namespace:

...

Book title

This, as far as I know, would _not_ conflict with any specification in any way, and would be straight-forward for the client to parse.

Alternatively, a separate node might be included, although I don't know if the Daisy spec would frown on this:

Book title

Author name

Either of these XML-based solutions would be infinitely more robust and flexible than the $-trick.

To quote [Nokogiri](http://nokogiri.org/):

> XML is like violence - if it doesn’t solve your problems, you are not using enough of it.

---------

A third option – which would still be against the Daisy spec, but not _more_ against it than the $-trick already is – would be to use the `

` node for JSON-data:

{"title": "Book title", "author": "Author name"}

Again, this would be straight-forward for the client to parse, and infinitely flexible.

And Ke$ha can't ruin it.