An XML2Object revisited class.
Basically it works in the same ways as the previius one, but now in the parseXML method it can be defined a 2nd parameter which will tell to the parser to put all xml nodes into arrays. In this way all variables created into the returned object will be stored into array. for example:
import it.sephiroth.XMLObject; myxml.onLoad = function(){ var data = new XMLObject().parseXML( this, true ); }
The second addition to this class is the parseObject method, which will convert any object into an xml. for example, this code:
import it.sephiroth.XMLObject; myobject = { attributes : { name : "custom object", type : 1 }, item : [ { name : "Varese", code : "VA" }, { name : "Milano", code : "MI" } ], channel : { name : "City", country : "Italy" } } data = new XMLObject().parseObject(myobject,"TEST");
will produce this xml string:
<?xml version="1.0"?> <TEST type="1" name="custom object"> <item> <name>Varese</name> <code>VA</code> </item> <item> <name>Milano</name> <code>MI</code> </item> <channel> <name>City</name> <country>Italy</country> </channel> </TEST>
And here’s the class code: XMLObject.as
Share with...