I have a server Implementation of ECMA Script including the ability to use E4X. Because this is pretty elegant for people don't know JavaScript and JSON Notation and we want to make an API which is most easy to learn i want to use this for my API.
I'm currently evaluating if i can use this in my environment. One Showstopping feature that i must use is to convert those XML Objects of E4X into JSON compatible JavaScript Objects or Strings on the fly. I can't use XSLT here because i have to stay inside JavaScript.
So the question is, is there an easy way to convert E4X XML Elements into JSON? Or do i have to write some code to convert it myself?
You can use XSLT to convert your XML to JSON.
For instance using: http://code.google.com/p/xml2json-xslt/
However you can end up with a very XMLish and unnecessarily complex JSON. That will make your code more difficult to write and maintain.
An API is generally meant to be stable in time, so may be some dedicated XSLT for each calls may be a better option than a generic one.
精彩评论