XML DOC from an Array

how can I create a XML docuement in ActionScript that looks like this

<obj>1st post
<obj>reply to 1st</obj>
</obj>
<obj>2nd post</obj>
<obj>3rd post
<obj>reply to 3rd
<obj>reply to 2nd of 3rd post</obj>
</obj>
</obj>
<obj>4th post</obj>

from this array of data…



core = new Array();
core[0] = new Array(4);
core[0][0] = 1;
core[0][1] = 0;
core[0][2] = 1;
core[0][3] = "1st post";
core[1] = new Array(4);
core[1][0] = 2;
core[1][1] = 0;
core[1][2] = 2;
core[1][3] = "2nd post";
core[2] = new Array(4);
core[2][0] = 3;
core[2][1] = 0;
core[2][2] = 2;
core[2][3] = "3rd post";
core[3] = new Array(4);
core[3][0] = 4;
core[3][1] = 0;
core[3][2] = 2;
core[3][3] = "4th post";
core[4] = new Array(4);
core[4][0] = 5;
core[4][1] = 1;
core[4][2] = 1;
core[4][3] = "REPLY TO 1ST POST";
core[5] = new Array(4);
core[5][0] = 6;
core[5][1] = 3;
core[5][2] = 2;
core[5][3] = "REPLY TO 3RD POST";
core[6] = new Array(4);
core[6][0] = 7;
core[6][1] = 6;
core[6][2] = 2;
core[6][3] = "REPLY TO 2ND OF 3RD POST";

kind of at a lost trying to figure all the if() – for() etc… out

I would use a recursive function that basically builds a tree data structure (that reflects the heirarchy of the threads) and then traverse the tree to output the XML.

However, before I give you an example, I need to understand if the numbers in your array are significant in understanding the thread structure, or if you are solely going off the words (that would be a pain). At the moment, I can’t figure out the significance of the 2nd and 3rd numbers stored with each message.

It seems like the first number is the post number, and the second number is the “reply_to” number and the third number is maybe the “reply_to_sub” number, but if that’s the case, you made some mistakes in your data entry…

  • Jim

PS. Although I love Flash, it wouldn’t be my first choice for implementing a messaging system…