# XML Difficulty: Insert children into nested nodes

**URL:** https://forum.kirupa.com/t/xml-difficulty-insert-children-into-nested-nodes/295530
**Category:** flash
**Created:** [September 1, 2009, 12:47am UTC](https://forum.kirupa.com/t/xml-difficulty-insert-children-into-nested-nodes/295530 "2009-09-01T00:47:07Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![madhat](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@madhat](https://forum.kirupa.com/u/madhat)
#### Post date: [September 1, 2009, 12:47am UTC](https://forum.kirupa.com/t/xml-difficulty-insert-children-into-nested-nodes/295530/1 "2009-09-01T00:47:07Z")

</div>

Hi all,  
I am trying to format some XML and am having trouble inserting child nodes into a certain node. I am trying to create a loop that inserts the following child ( **\<file href=“slide\_5.swf” /\>** ) into the \*\*manifestXML.resources.resource \*\*node. I have been working on this for hours and it’s killing me. Any insight greatly appreciated!

```auto
 
 
[COLOR=#993300]function[/COLOR] formatXML[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR]:[COLOR=#993300]void[/COLOR][COLOR=#000000]{[/COLOR]
    [COLOR=#993300]var[/COLOR] manifestXML:[COLOR=#993300]XML[/COLOR] =
    <manifest xmlns=[COLOR=#0000ff]'http://www.imsproject.org/xsd/imscp_rootv1p1p2'[/COLOR]>
        <organizations [COLOR=#993300]default[/COLOR]=[COLOR=#0000ff]'ORG-596EF3D7-197B-DC31-43D9-D358CC550899'[/COLOR]>
            <organization identifier=[COLOR=#0000ff]'ORG-596EF3D7-197B-DC31-43D9-D358CC550899'[/COLOR] structure=[COLOR=#0000ff]'hierarchical'[/COLOR]>
                <title>[COLOR=#000000]{[/COLOR]orgVar[COLOR=#000000]}[/COLOR]</title>
                <item identifier=[COLOR=#0000ff]'ITEM-9756ED80-D162-DF66-901B-69E7BED29892'[/COLOR] isvisible=[COLOR=#0000ff]'true'[/COLOR] identifierref=[COLOR=#0000ff]'RES-B57BD0E4-821C-19E1-EF41-2C88D138C2FB'[/COLOR]>
                    <title>[COLOR=#000000]{[/COLOR]scoVar[COLOR=#000000]}[/COLOR]</title>
                </item>
            </organization>
        </organizations>
        <resources>
            <resource identifier=[COLOR=#0000ff]'RES-B57BD0E4-821C-19E1-EF41-2C88D138C2FB'[/COLOR] [COLOR=#993300]type[/COLOR]=[COLOR=#0000ff]'webcontent'[/COLOR] adlcp:scormtype=[COLOR=#0000ff]'sco'[/COLOR] href=[COLOR=#000000]{[/COLOR]indexVar[COLOR=#000000]}[/COLOR]>
               [COLOR=#f000f0]*//I WANT TO INSERT NEW NODES IN HERE*[/COLOR]
              </resource>      
        </resources>
    </manifest>;
    [COLOR=#f000f0]*//THIS IS THE CODE THAT IM TRYING TO USE TO INSERT NEW NODES*[/COLOR]
    manifestXML.[COLOR=#000000]insertChildAfter[/COLOR][COLOR=#000000]([/COLOR]manifestXML.[COLOR=#000000]resources[/COLOR].[COLOR=#000000]resource[/COLOR], <file href=[COLOR=#0000ff]"slide_5.swf"[/COLOR] />[COLOR=#000000])[/COLOR];
    textOutput.[COLOR=#993300]text[/COLOR] = manifestXML.[COLOR=#000000]toXMLString[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]

```
