0

I am building an application which works on data from column based database. I am getting the data as arrays where each array represents a columns in the table returned by the database. The data contain parent, child relationship. The arrays may look like that (view same index in each array as a row in a normal SQL database):

[0] empty   [1] empty   [2] ID-A  [3] ID-B  [4] ID-B <-- this represents nodes' parents  
[0] ID-A    [1] ID-A    [2] ID-B  [3] ID-C  [4] ID-D <-- this represents nodes' labels  
[0] 100     [1] 200     [3] 300   [4] 150   [4] 150  <-- this represents values associated with nodes

Of course they are much bigger. Up to 100000 elements. All I want to do, is create the following XML from the data I have:

<root>  
   <node label="ID-A" value="300">  
      <node label="ID-B" value="300">  
          <node label="ID-C" value="150"/>  
          <node label="ID-D" value="150"/>  
      </node>
   </node>
</root>

Notice that for ID-A there is only one entry at the top level, and it's value is the sum for all its entries in the array.

I do not know the depth of the structure beforehand and any IDs or values. How do I create the XML so that I will be later able to display it in a tree control? What I want to do is iterate through array, each time adding a node for an ID if it does not exist, but just update the value (add it to the current one) if the ID exists. I can create the first layer, but I have trouble accessing and updating appropriate elements at bigger depths. Basically, how do would I add a ID-E below ID-B to the XML above, in order to achieve the following:

<root>  
   <node label="ID-A" value="300">  
      <node label="ID-B" value="300">  
          <node label="ID-C" value="150"/>  
          <node label="ID-D" value="150"/>  
          <node label="ID-E" value="sth"/>
      </node>
   </node>
</root>

Or would it maybe actually be beter to build an ArrayCollection with children from the arrays I have? I am new to Flex so I can't tell myself what would be more efficient.

1
  • which database you are using?, could you change format of result from database? Commented Jul 24, 2012 at 4:08

1 Answer 1

1

Converting 100k rows into XML could be very slow and XML takes up a lot of memory, which is wasted if it's just for use as a tree data provider. If you just need to do that to view the data in a tree, perhaps you can keep it in an Array, but use a customer tree dataDescriptor to define the hierarchy. http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/Tree.html#dataDescriptor

Sign up to request clarification or add additional context in comments.

1 Comment

Would converting it to ArrayCollection be faster? I think it might be quite tricky to define a custom dataDescriptor for the type of data I have

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.