X

在XMLList里插入节点

var xml:XML = new XML(  <data>
                            <user>
                                <user id="1"/>
                                <user id="2"/>
                            </user>
                        </data> );

var xmlList:XMLList = xml.user.user;
var myXML:XML = new XML(<user id="3"/>);
insertXML(xmlList, myXML);
trace("-------- xmlList -----------");
trace(xmlList);
trace("---------- xml -------------");
trace(xml);

function insertXML(xmlList:XMLList, xml:XML):void
{
    // 修改xmlList,建议用这个
    xmlList[xmlList.length()] = xml;
    // 不修改xmlList 
    //xmlList.parent().appendChild(xml);
}

This post was last modified on 2019 年 03 月 04 日 01:31

View Comments (1)

This website uses cookies.