JSON API call from XForms

Hello,

I have recently added JSON API support in XSLTForms 
(http://www.agencexml.com/xsltforms) because of the cross domain 
restriction.

The GET method with a query string allows to activate methods of such 
APIs. For cross domain workaround, an extra parameter, usually named 
"callback", will wrap the JSON results in a Javascript function call: 
adding a script element with the corresponding src attribute will call 
the callback function with the JSON structure.

Just to see how it might work, I added a test in XSLTForms whether the 
submission is a cross domain one or not. If it is, as a default mode, it 
considers it's a JSON API call and automatically adds the callback 
parameter with the name of the function which will be able to convert a 
JSON structure into an XML instance. Serialization is set to "none" in 
this case.

Here is a link to a demo: 
http://www.agencexml.com/jsoncallback/wikipediasearch.xml

Just look at the source to see the XForms document.

The JSON to XML translation was not very easy to write because JSON 
arrays might appear without any name and I decided to create elements 
named "array" and "item" as a workaround. I also had to add a root 
element, named "root" of course ;-)

Thank you for your feedbacks!

Best regards,

Alain Couthures
<agenceXML>
http://www.agencexml.com
Bordeaux, France

Received on Friday, 5 February 2010 16:32:43 UTC