Re: [Flashcoders] Which Data Structure is good for this?
I think Steven has already sent you the XML2AS code which is great. You could also try the XMLParser class I wrote which is similar but adds a few features. You can basically throw your XML document at it and it'll spit back an object with properties & arrays that follow the naming convention from your original XML document which makes it a lot easier to get at the data (in my opinion at least). It'll retain your hierarchy too. Snag it at: http://www.greensock.com/ActionScript/XMLParser Hope it helps. Jack > -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: > > > > > > > > > > > > > > < backgrounds id="125" file="foo/etc/bg.png"/> > > > > > > > > > > > > > > > ... 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
Re: [Flashcoders] Which Data Structure is good for this?
On 12/12/06, Sascha <[EMAIL PROTECTED]> wrote: Thanks Michael! You're right, E4X is sweet but in this case there are too many things that hang onto it later so I want to create a custom data holder that is more lightweight and fits the needs exactly. Using an object with own API for every hierarchy would also be overkill. Thanks a lot for the efforts though! I might also try utilizing the Proxy class as there properties later that are not known from the beginning. I'm not really sure what your requirements are, then. Would be interested to see your ultimate solution. -- T. Michael Keesey The Dinosauricon: http://dino.lm.com Parry & Carney: http://parryandcarney.com ISPN Forum: http://www.phylonames.org/forum/ ___ 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
RE: [Flashcoders] Which Data Structure is good for this?
Thanks Michael! You're right, E4X is sweet but in this case there are too many things that hang onto it later so I want to create a custom data holder that is more lightweight and fits the needs exactly. Using an object with own API for every hierarchy would also be overkill. Thanks a lot for the efforts though! I might also try utilizing the Proxy class as there properties later that are not known from the beginning. Cheers, Sascha > -Original Message- > From: [EMAIL PROTECTED] [mailto:flashcoders- > [EMAIL PROTECTED] On Behalf Of T. Michael Keesey > Sent: Tuesday, 12 December, 2006 14:00 > To: Flashcoders mailing list > Subject: Re: [Flashcoders] Which Data Structure is good for this? > > On 12/11/06, Sascha <[EMAIL PROTECTED]> wrote: > > 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: > [snipped] > > The e4x functions make dealing with XML objects s nice that I > don't see any particular reason to convert it to something else. > > But, if you insist, how about a data model package with classes like so: > > Model > public function get xml():XML; > public function set xml(value:XML):void > > ResourceList extends Model > public function getDisplay(type:uint):Display; > public function get data():Data; > override public function set xml(value:XML):void > > Display extends Model > public function get propertyCount():uint; > public function get backgroundCount():uint; > public function get objectCount():uint; > public function getProperty(index:uint):Property; > public function getBackground(index:uint):Background; > public function getObject(index:uint):DisplayObject; > override public function set xml(value:XML):void > > ... so on and so forth > > -- > T. Michael Keesey > The Dinosauricon: http://dino.lm.com > Parry & Carney: http://parryandcarney.com > ISPN Forum: http://www.phylonames.org/forum/ > ___ > 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
Re: [Flashcoders] Which Data Structure is good for this?
On 12/11/06, Sascha <[EMAIL PROTECTED]> wrote: 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: [snipped] The e4x functions make dealing with XML objects s nice that I don't see any particular reason to convert it to something else. But, if you insist, how about a data model package with classes like so: Model public function get xml():XML; public function set xml(value:XML):void ResourceList extends Model public function getDisplay(type:uint):Display; public function get data():Data; override public function set xml(value:XML):void Display extends Model public function get propertyCount():uint; public function get backgroundCount():uint; public function get objectCount():uint; public function getProperty(index:uint):Property; public function getBackground(index:uint):Background; public function getObject(index:uint):DisplayObject; override public function set xml(value:XML):void ... so on and so forth -- T. Michael Keesey The Dinosauricon: http://dino.lm.com Parry & Carney: http://parryandcarney.com ISPN Forum: http://www.phylonames.org/forum/ ___ 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
RE: [Flashcoders] Which Data Structure is good for this?
Thanks Steven! Forgot to mention that I'm using AS3. I will try to write your method in AS3 and see if it fits my needs. Cheers, Sascha > -Original Message- > From: [EMAIL PROTECTED] [mailto:flashcoders- > [EMAIL PROTECTED] On Behalf Of Steven Sacks | BLITZ > Sent: Tuesday, 12 December, 2006 13:05 > To: Flashcoders mailing list > Subject: RE: [Flashcoders] Which Data Structure is good for this? > > 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: > > > > > > > > > > > > > > > > > > > > > > > > > > > > < backgrounds id="125" file="foo/etc/bg.png"/> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > ... 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 ___ 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
RE: [Flashcoders] Which Data Structure is good for this?
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: > > > > > > > > > > > > > > < backgrounds id="125" file="foo/etc/bg.png"/> > > > > > > > > > > > > > > > ... 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