PDA

View Full Version : How to add nodes in xml file at specific position?



psych
July 22nd, 2007, 09:26 AM
Lets say i have the following xml file which i load in Flash:



<example>
<items title="something>
<img id="image"/>
<audio id="audio" />
<text id="text"/>
</items>
</example>
And i would like to add the following line:


<video id="video">
after the <audio> node so that input xml looks like this:



<example>
<items title="something>
<img id="image"/>
<audio id="audio"/>
<video id="video"/>
<text id="text"/>
</items>
</example>
I've done the loading part but can't figure it out how to add new node at specific position. Can someone please show me how to do that ?

thanks a lot

mathew.er
July 22nd, 2007, 09:40 AM
var xml : XML =
<example>
<items title="something">
<img id="image" />
<audio id="audio" />
</items>
</example>;

var videoNode : XML = <video id="video" />

xml.items.insertChildAfter ( xml.items.audio, videoNode );

trace ( xml.toXMLString () )

psych
July 22nd, 2007, 10:34 AM
Thank you very much Mathew, this will help me a lot.

cheers