how to remove xmlnode within a foreach loop?

前端 未结 5 1942
北荒
北荒 2021-01-07 04:04

At the following code i use foreach loop to check each node in nodelist and remove some of them. after i remove one node the foreach loop throw the following error: \"The el

5条回答
  •  庸人自扰
    2021-01-07 04:37

    Use for loop instead from

    for(I=length-1;I>=0;I--)
    

    For each is used for enumerating and you cannot delete while enumerating the list. Also the loop must start from the last element to avoid any shift when you delete an element.

提交回复
热议问题