Removing DOM nodes when traversing a NodeList

前端 未结 7 881
南方客
南方客 2020-12-06 04:54

I\'m about to delete certain elements in an XML document, using code like the following:

NodeList nodes = ...;
for (int i = 0; i < nodes.getLength(); i++)         


        
7条回答
  •  爱一瞬间的悲伤
    2020-12-06 05:42

    The Practical XML library now contains NodeListIterator, which wraps a NodeList and provides full Iterator support (this seemed like a better choice than posting the code that we discussed in the comments). If you don't want to use the full library, feel free to copy that one class: http://practicalxml.svn.sourceforge.net/viewvc/practicalxml/trunk/src/main/java/net/sf/practicalxml/util/NodeListIterator.java?revision=125&view=markup

提交回复
热议问题