function XML2AS(n, r) { var a, d, k; if (r[k=n.nodeName] == null) r = ((a=r[k]=[{}]))[d=0]; else r = (a=r[k])[d=r[k].push({})-1]; if (n.hasChildNodes()) { if ((k=n.firstChild.nodeType) == 1) { r.attributes = n.attributes; for (var i in k=n.childNodes) XML2AS(k[i], r); } else if (k == 3) { a[d] = new String(n.firstChild.nodeValue); a[d].attributes = n.attributes; } }else r.attributes = n.attributes; }
Usage example: var xmlObj:Object = {}; XML2AS(xml.firstChild, xmlObj); var dType:String = xmlObj.resourceList[0].display[0].attributes.type; var pArray:Array = xmlObj.resourceList[0].display[0].displayProperties[0].property; var i:Number = pArray.length; while (i--) { trace(pArray[i].attributes.name + "," + pArray[i].attributes.value); } > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Sascha > Sent: Monday, December 11, 2006 7:54 PM > To: 'Flashcoders mailing list' > Subject: [Flashcoders] Which Data Structure is good for this? > > I would be interested in recommendations about what kind of > data structure is best used in the following situation. > I'm loading in a XML file with a typical recursive structure, > then the data from it should be parsed into a data storage > object and this data should be accessible globally through > the application. The XML file has a structure like this: > > <resourceList> > <display type="1"> > <displayProperties> > <property name="foo" value="doo"/> > <property name="fee" value="faa"/> > </displayProperties> > <displayObjects> > <object id="1" file="foo/etc/file.xml"/> > <object id="2" file="foo/etc/file2.xml"/> > <object id="3" file="foo/etc/file3.xml"/> > </displayObjects> > <backgrounds> > < backgrounds id="125" file="foo/etc/bg.png"/> > </ backgrounds> > </display> > <data> > <dataTypes> > <property name="foo" value="doo"/> > <property name="fee" value="faa"/> > </dataTypes> > </data> > <etc> > <somethingElse> > <property name="foo" value="doo"/> > </ somethingElse > > </etc> > > ... The XML is being extended by the time but it retains the > shown hierarchical structure. I want to be able to keep a > similar structure in memory but I don't want to keep it as an > XML object. I was thinking about using a custom object and > populate it with HashMaps but then the hierarchy would be too flat. > I would appreciate it if somebody could give me some > suggestions what kind of data structure is a good choice for > this as I don't have much experience with trees, lists and > other more complex structures. > > Thanks a lot, > Sascha > > > _______________________________________________ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com http://training.figleaf.com > _______________________________________________ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com