|
New to the CF scene
Join Date: Jul 2012
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
|
Saving a Multidimensional Array into an XML using JavaScript
So I have a multidimensional array that looks like this:
Code:
var map = [[0, 0, 0, 0, 0, 0, 0],
[0, 3, 0, 0, 2, 0, 0],
[0, 0, 0, 0, 4, 0, 4],
[0, 0, 0, 0, 5, 0, 5],
[0, 0, 0, 0, 0, 0, 1],
[0, 0, 2, 5, 0, 0, 0],
[0, 0, 0, 2, 0, 0, 0],
[0, 4, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0]];
And i would like to save it into my XML file.
My XML file looks like the following:
Code:
<TileMaps>
<Level> <!-- Level 1 -->
<map>[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 3, 2, 4, 0, 0, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]</map>
</Level>
<Level> <!-- Level 2 -->
<map>[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 3, 2, 4, 0, 0, 0, 0, 0, 1],
[1, 0, 2, 4, 0, 0, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]</map>
</Level>
</TileMaps>
So when i add the array i would like it to be placed within the XML file within the:
Code:
<Level><map> ARRAY HERE </map></Level>
How would i be able to add the map variable from the Javascript into a <map></map> node within the XML file? I would need to be able to return the <map> number aswel. For example if i already had 4 <level><map>[[0,0],[0,0]]</map></level> then i would need to add it to the end of those and return the number 5 to show thats what the level number is.
Thanks
|
|