# Trouble with adding xml node

**URL:** https://forum.kirupa.com/t/trouble-with-adding-xml-node/314593
**Category:** flash
**Created:** [October 3, 2010, 10:10am UTC](https://forum.kirupa.com/t/trouble-with-adding-xml-node/314593 "2010-10-03T10:10:40Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![shaji](https://avatars.discourse-cdn.com/v4/letter/s/5fc32e/32.png) [@shaji](https://forum.kirupa.com/u/shaji)
#### Post date: [October 3, 2010, 10:10am UTC](https://forum.kirupa.com/t/trouble-with-adding-xml-node/314593/1 "2010-10-03T10:10:40Z")

</div>

It seemed to me that adding nodes to an xml would be an easy task, but this one result seems to be bit illogical to me. Don’t know whether I doing it wrong or is it possibly a bug.

I have a xml with list of activities nodes are to be added. I keep adding the activities node in a sequence. But then when I trace the xml to find its not in a sequence. I have code below

```auto

//Assuming there are two nodes to be added in the activity XML
var typeOne:XML =<quiz type="1" ></quiz>;
var typeTwo:XML =<quiz type="2" ></quiz>;        

//Activity XML to which activity xml would be added as per requirement
var app_xml:XML = new XML(<quizData><global_properties></global_properties><allquiz></allquiz></quizData>);

//variable to keep track of total activities added
var _currentQuestion:int = 0;

//Array to see the order in which activity nodes are inserted
var temp:Array = [];

//function with logic to make the insertion of activity nodes

function addQuiz(type:int){
    if(type == 0){
        app_xml.allquiz.quiz[_currentQuestion++] = typeOne;
        temp.push("mmcq");
    }else{
        app_xml.allquiz.quiz[_currentQuestion++] = typeTwo;
        temp.push("input");
    }
    
    trace(app_xml);
    trace(temp);
}

//add activity nodes
addQuiz(0);
addQuiz(1);
addQuiz(0);
addQuiz(1);

```

now the trace below

```auto

<quizData>
  <global_properties/>
  <allquiz>
    <quiz type="1"/>
  </allquiz>
</quizData>
typeOne
------------------------------------------------------------------
<quizData>
  <global_properties/>
  <allquiz>
    <quiz type="1"/>
    <quiz type="2"/>
  </allquiz>
</quizData>
typeOne,typeTwo
------------------------------------------------------------------
<quizData>
  <global_properties/>
  <allquiz>
    <quiz type="1"/>
    <quiz type="2"/>
    <quiz type="1"/>
  </allquiz>
</quizData>
typeOne,typeTwo,typeOne
------------------------------------------------------------------
<quizData>
  <global_properties/>
  <allquiz>
    <quiz type="1"/>
    <quiz type="2"/>
    <quiz type="2"/>
    <quiz type="1"/>
  </allquiz>
</quizData>
typeOne,typeTwo,typeOne,typeTwo
------------------------------------------------------------------

```

When the fourth node is entered its not in the fourth place rather in third place.

This is my issue, I want them in the order they are entered. Array returns in right order.

Any help in resolving the issue or an alternate solution would be appreciated.
