XML2Object revisited

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

  • In using your XMLObject class; I’m pulling in an XML object, converting it to Flash Object, manipulating the data and converting it back to XML (to save). I noticed a bug (around line 103) that was from = new XML(this.xml). By changing it to from = this.xml, it worked (passed the compile anyway).
    Also when converting an object back to XML, all my tags and attributes got reversed and I ended up with a bunch of ‘data’ tags. I REALLY need the XML structure to be exactly the same and I found the solution:
    After studying the code, I wrote a reverseProps routine that reverses the order of the properties of an object. I also send the root node name as ‘data’. After removing the and tags the XML getting saved looks exactly like the XML loaded.
    I place my reverseProps routine as the 1st line in parseAttributes() and as the 1st line after case Object.prototype in translateObject()
    My reverseProps routine is simple:
    private function reverseProps(obj:Object):Object{
    var property = [];
    var value = [];
    for( a in obj){
    obj = {};
    for(var a:Number=0; a