W3C home > Mailing lists > Public > www-forms@w3.org > February 2010

JSON API call from XForms

From: COUTHURES Alain <alain.couthures@agencexml.com>
Date: Fri, 05 Feb 2010 17:32:50 +0100
Message-ID: <4B6C4832.5020608@agencexml.com>
To: www-forms@w3.org

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

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: 

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
Bordeaux, France
Received on Friday, 5 February 2010 16:32:43 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:37:59 UTC