# Xml insertBefore problem

**URL:** <https://forum.kirupa.com/t/xml-insertbefore-problem/217214>\
**Category:** Uncategorized\
**Created:** [February 24, 2007, 10:29am UTC](https://forum.kirupa.com/t/xml-insertbefore-problem/217214 "2007-02-24T10:29:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![monkus](https://avatars.discourse-cdn.com/v4/letter/m/41988e/32.png) [@monkus](https://forum.kirupa.com/u/monkus)\
**Post date:** [February 24, 2007, 10:29am UTC](https://forum.kirupa.com/t/xml-insertbefore-problem/217214/1 "2007-02-24T10:29:27Z")

</div>

I have a xml file with structure like this:  
\<root\>  
\<images\>  
\<name\>xxxxxxxx\</name\>  
\<thumb\>zzzz\</thumb\>  
\<caption\>ttttt\</caption\>  
\</images\>  
\<images\>  
\<name\>yyyyyyyyy\</name\>  
\<thumb\>uuuuuu\</thumb\>  
\<caption\>oooooo\</caption\>  
\</images\>  
.  
.  
\</root\>

the xml is created in flash, now when I try to modify it, say call out a particular set of \<images /\>, I remove the node first, then create a new one, then when I try to insert it back to the xml, this is what happened:

i = 10;  
var insertPoint = my\_xml.firstChild.childNodes\*;  
var newNode = new XML ( new node details here );  
my\_xml.insertBefore (newNode, insertPoint);

result:  
\<root\>  
\<images\>all the nodes in between as per normal\</images\>  
\</root\>

\<images\>  
\<name\>new name\</name\>  
\<thumb\>new thumb\</thumb\>  
\<caption\>new caption\</caption\>  
\</images\>

// this set is supposed to be “inserted” to a insertpoint and before \</root\>, but it is now outside \<root\>, can any one help?

thanks heaps
