xml nodes will not delete despite calling “delete”

前端 未结 1 672
鱼传尺愫
鱼传尺愫 2021-01-17 00:23

I\'m trying to use the delete keyword to remove nodes from an xml file and it just plain won\'t work.

Here\'s a stripped down example of what I\'m working with. Eve

相关标签:
1条回答
  • 2021-01-17 01:02

    Yo

    You need to do the 'for loop' in reverse. This goes for removing items in any collection/list via an iteration loop.

    When an item is deleted (e.g. index 2 when j is 2), the next item in the List fills the space left by the deleted item (e.g. index 3 becmoes index 2), but j gets increased to 3, and the shifted item (in index 2) gets skipped. The following will work:

    var _xmlList:XMLList=_sourceXML.i;
    
    for (var j:int=_xmlList.length() - 1; j >= 0 ; j--)
    {                   
        if (_xmlList[j].deleteme == 1)
        {
            delete _xmlList[j];                     
        }                   
    }
    
    0 讨论(0)
提交回复
热议问题