-1

Possible Duplicate:
XML <-> JSON conversion in Javascript

I have a somewhat large store of data in Javascript that I need to eventually turn into an XML file on the PHP server. It seems quite cumbersome to turn the data in a JSON object, send this to PHP through an ajax POST and then create an XML object with a PHP library and create the XML file.

It seems that I would prefer to create some sort of XML object on the javascript and then send this to the PHP with a dojo/ajax call. Sadly I have not been able to find any good Dojo or Javascript libraries to create the XML and it seems like it would tedious and error prone to create the XML by hand. Is there a good way to create XML in Javascript? Am I go about this wrong? Should I just be sending all of the data as large JSON and then deciphering it in PHP?

Community
  • 1
  • 1
Mike2012
  • 7,629
  • 15
  • 84
  • 135

1 Answers1

1

I'd pass the JSON to PHP, decode the JSON into an array and then turn the array into an XML doc.

To turn the JSON into an array use:

    $data_array = json_decode('{"JSON":"STRING"}', true);

And then check out this post on saving an array as xml.

Community
  • 1
  • 1
  • Another way to convert a JSON object to XML in PHP http://stackoverflow.com/questions/856833/is-there-some-way-to-convert-json-to-xml-in-php – Diego Pino Oct 08 '12 at 20:37