XML Difficulty: Insert children into nested nodes

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!

 
 
[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]