Hi,
 
My situation is I have a heavy array, named source.
 
Source has elements in the order [CA,12,25,35,40,
WA,23,43,54,65,
FL,26,46,14,69,
TX,03,83,55,15,
IL,21,49,84,95]
 
So basically the source array elements are in the order of: A state name then 
four properties and then again a state name and four properties and so on.
I can’t hard code anything other than first one is a state name and will have 4 
properties. The values in properties are dynamic.
I want to display this in the form of a tree in flex. Can I do it. If so, 
please help. Thanks.


Best Regards,
Venkat Maddali. 

 

From: "Tandon, Rishi" <rishitandon...@yahoo.com>
>To: "flexcoders@yahoogroups.com" <flexcoders@yahoogroups.com>
>Sent: Tuesday, August 30, 2011 11:40 PM
>Subject: Re: [flexcoders] Array to XML?
>
>  
>This might help:
>
>
>/**
>* Object To XML Conversion Mechanism For Structure
>* @param xmlData
>* @return 
> * @author rtandon 
> */
>private static function makeXML(data:Object,rootNodeName:String):XML{
>data = ObjectUtil.copy(data);
>var xmlData:XML = new XML();
>var dataNode:XML;
>xmlData = <{rootNodeName}></{rootNodeName}>;
>for (var prop:* in data){
>dataNode = new XML();
>if(data[prop] is String || data[prop] is int || data[prop] is Number 
>|| data[prop] is Boolean){
>dataNode = <{prop}>{data[prop]}</{prop}>;
>xmlData = xmlData.appendChild(dataNode);
>}else if(data[prop] is Array || data[prop] is ArrayCollection){
>xmlData = xmlData.appendChild(makeXMLCollection(data[prop],prop));
>}else{
>xmlData = xmlData.appendChild(makeXML(data[prop],prop));
>}
>}
>return xmlData;
>}
>/**
>* Object To XML Conversion Mechanism For Table 
>* @param data
>* @param rootNodeName
>* @return 
>* @author rtandon
>*/
>private static function makeXMLCollection(data:Object,rootNodeName:String):XML{
>data = ObjectUtil.copy(data);
>var xmlData:XML = new XML();
>var itemNode:XML;
>xmlData = <{rootNodeName}></{rootNodeName}>;
>for( var i:int;i<data.length;i++){
>xmlData = xmlData.appendChild(makeXMLCollectionItem(data[i]));
>}
>return xmlData;
>}
>private static function makeXMLCollectionItem(data:Object):XML{
>data = ObjectUtil.copy(data);
>var xmlData:XML = new XML();
>var dataNode:XML;
>xmlData = <item></item>;
>for (var prop:* in data){
>dataNode = new XML();
>if(data[prop] is String || data[prop] is int || data[prop] is Number 
>|| data[prop] is Boolean){
>dataNode = <{prop}>{data[prop]}</{prop}>;
>xmlData = xmlData.appendChild(dataNode);
>}else if(data[prop] is Array || data[prop] is ArrayCollection){
>xmlData = xmlData.appendChild(makeXMLCollection(data[prop],prop));
>}else{
>xmlData = xmlData.appendChild(makeXML(data[prop],prop));
>}
>}
>return xmlData;
>}
>From: Venkat M <venkat_...@yahoo.com>
>To: "flexcoders@yahoogroups.com" <flexcoders@yahoogroups.com>
>Sent: Wednesday, August 31, 2011 5:59 AM
>Subject: [flexcoders] Array to XML?
>
>  
>  
>Hi group,
> 
>Can some one please help me in converting an array into an xml file or a 
>similar hierarchical data structure to be used for a tree component! 
> 
>Imagine a case I have an array A with values A1,A2,A3,A4,   B1,B2,B3,B4, ….. 
>Z1,Z2,Z3,Z4.
>Can I have an XML like 
><A>
>                <A1></A1>
>                ..
>                ..
></A>
>. . . . 
>. . . . 
><Z>
>                <Z1></Z1>
>                ..
>                ..
></Z>
> 
>So that I can directly link it to a tree component? Kindly help out!!
> 
>Best Regards,
>Venkat Maddali. 
>
> 
>

Reply via email to