views:

842

answers:

4

I am looking for a best proved way to serialize JavaScript objects to XML, that could be sent to server further in Ajax style.

Just googling I've found some options like http://svn.mirekrusin.com/pub/javascript/to_xml/trunk/to_xml.js, but does somebody has proved experience and could recommend any specific library?

A: 

That does not really answer your question, but maybe you could use JSON instead of XML.

Guido
Actually I am trying to switch from JSON to XML...
Gennady Shumakher
A: 

Not an answer, but can I ask why you are switching from JSON to XML? I tend to favour XML, so I'm not criticising, but curious.

I think XML can give a better domain representation; but JSON tends to be better if your domain is objects (it being an object notation).

13ren
A: 

I dont know if there are fameworks that will do this for you but...

// Define class constructor var SampleObject1 = function() { this.name = 'MySampleObject'; this.id = 1; this.seed = 1.009; this.createdAt = new Date(); this.obj = null; };

// Create instance of serializer var serializer = new Ant.Serializer();

// Register SampleObject1, so serializer gets to know how to deal with such objects serializer.register('SampleObject1', SampleObject1);

// Create data that will be serialized var object = new SampleObject1(); object.obj = new SampleObject1();

// Serialize and get string representation var xml = serializer.save(object).toString();

// Displays (formatting is changed): // // MySampleObject // 1 // 1.009 // // // // // // MySampleObject // 1 // 1.009 // // // // // // // WScript.echo(xml);

// Displays: MySampleObject WScript.echo(serializer.load(xml).name);

p01nd3xt3r
+1  A: 

Try this:

Converting Between XML and JSON by Stefan Goessner

jim0thy