View Full Version : how to change XML string to ArrayColeection
maarek
10-03-2007, 12:06 AM
I have the string with XML tags:
<Root>
<kat id="0" label="dfgdfgdf"></kat>
<kat id="1" label="dfgd"></kat>
</Root>
and I need to have it changed into ArrayColeection.
Jim Freer
10-03-2007, 01:13 AM
Just out of curiosity why do you want to do that? I suppose you could create an ArrayCollection of Objects that contain the properties, “id” and “label” but on the surface it would seem easier to use the XML object directly.
maarek
10-03-2007, 01:18 AM
I have to make some changes in old project and I have to get the data from MySQL database as an ArrayCllection. Can you please tell me how to build ArrayCollection from such XML data:
<Root>
<kategoria id="0" label="POLECAMY" produkty=""></kategoria>
<kategoria id="1" label="ARTYKUŁY SPOŻYWCZE">
<children id="32" label="pieczywo">
<children id="201" label="pieczywo białe" produkty="" data="3" />
<children id="202" label="pieczywo pełnoziarniste" produkty="" data="3"/>
<children id="203" label="pieczywo chrupkie" produkty="" data="3"/>
<children id="204" label="inne" produkty="" data="3"/>
</children>
<children id="33" label="wędliny">
<children id="205" label="kiełbasy cienkie" produkty="" data="3"/>
<children id="206" label="kiełbasy grube" produkty="" data="3"/>
<children id="207" label="szynki, balerony, polędwice" produkty="" data="3"/>
<children id="208" label="pasztety" produkty="" data="3"/>
</children>
<children id="34" label="dania gotowe" produkty="" data="3" />
<children id="35" label="przekąski" produkty="" data="3" />
<children id="36" label="dania dla dzieci" produkty="" data="3" />
<children id="37" label="słodycze" produkty="" data="3" />
<children id="38" label="desery w proszku" produkty="" data="3" />
<children id="39" label="dodatki do ciast" produkty="" data="3" />
<children id="40" label="przyprawy i dodatki" produkty="" data="3" />
<children id="41" label="produkty sypkie, makarony" produkty="" data="3" />
<children id="41" label="przetwory owocowe" produkty="" data="3" />
<children id="42" label="przetwory warzywne" produkty="" data="3" />
<children id="43" label="przetwory mięsne" produkty="" data="3" />
<children id="44" label="przetwory rybne" produkty="" data="3" />
</kategoria>
</Root>
maarek
10-03-2007, 01:21 AM
I realised that I don't need to format my data from database to XML and the transform into ArrayCollection. I can create proper ArrayCollection manually but... in what way? And important is that the ArrayCollection was give to the site using mx:HTTPService and in debugger in Flex Builder 2 it's very large and I don't know from where I have to get the data.
Jim Freer
10-03-2007, 01:55 AM
Here's the code for creating an ArrayCollection of Objects from your first example. Your last post is more complicated but maybe you can figure it out from this code. I don't understand your most recent post. I still don't understand why you need an ArrayCollection. There are different ways to represent the data and still be encapsulated in an ArrayCollection.
var lvXml:XML =
<Root>
<kat id="0" label="dfgdfgdf"></kat>
<kat id="1" label="dfgd"></kat>
</Root>;
var lvArrayCollection:ArrayCollection = new ArrayCollection();
for each( var lvXmlChild:XML in lvXml.children() )
{
var lvObject:Object = new Object();
for each( var lvXmlAttribute:XML in lvXmlChild.attributes() )
{
lvObject[lvXmlAttribute.name().toString()] = lvXmlAttribute.toString();
} // for each
lvArrayCollection.addItem( lvObject );
} // for each
Jim Freer
http://freerpad.blogspot.com/
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.