[Playlist] xspf over json
Chris Anderson
jchris at mfdz.com
Sat Apr 28 22:40:34 UTC 2007
Sebastian,
There's a few libraries for general purpose XML -> JSON translation.
Here's a write up of one:
http://ajaxian.com/archives/badgerfish-translating-xml-to-json
The basic flaw with them is that in trying to make general
translations from XML to JSON, one loses JSON's principle benefit of
readability and terseness. By attempting to create JSON that loses no
information from the XML source, such that one could reverse the
translation, you end up storing a lot of extra information, and still
don't get the whole thing perfect. Some problems are the attribute
order on xml elements, as well as namespacing. Perhaps one can shovel
those things into Javascript Object Notation, but the result won't be
pretty.
The nice thing about an XSPF specific JSON format is that it can be
terse and readable, and still contain the data called for by the XSPF
spec. I haven't gotten into some of the more esoteric parts of the
spec (meta tags etc), but have implemented extensions - albeit only
those who's contents consist of key-value pairs. (elements with only
text node content in XML)
The lean subset of XSPF I've been working with has been enough to
handle all my needs for Grabb.it. I've got unit tests that ensure that
the XSPF I'm generating yields identical Javascript objects when
parsed on the client, as my JSPF strings yield, when eval'ed. I
haven't even tried running XSPF I didn't generate through the
javascript parser, so the results on richer data sets are still
undefined...
Lucas, I like jspf over xjs, as it is clearly more accurate.
I'm not sure how to proceed as far as interoperability. I contacted
the Songbird team today and offered them my parser, but it is not
general purpose, and I'll bet that's what they need. I'd like to make
a general purpose parser, but it seems like one could fall into the
trap of having to support full-featured xml including namespaces very
quickly.
Do you think a jspf as a limited subset of xspf has wings, or should I
shoot for a full implementation?
I hope to have the new version of Grabb.it deployed this coming week,
so you can all play with it and see these things in action.
--
Chris Anderson
http://jchris.mfdz.com
More information about the Playlist
mailing list