I need to walk a JDOM tree and make changes as I go along; at this point, changes are mostly adding new elements right now but could also include reordering elements or removing elements. All work is done on the same thread so there are no concurrency issues.

This turns out to be difficult because JDOM iterators can throw a ConcurrentModificationException if you try to add a node during traversal. From what I can see, JDOM uses lists instead of directly linking DOM nodes and this makes it difficult to do modifications on the fly.

I've seen a couple of recommendations on how to deal with this, such as deferring the adds until after the traversal is done, or building a new tree on the fly so that the traversed tree remains unchanged. These won't work for me because I need a consistent view of the tree as I modify it.

I'm beginning to suspect that JDOM just won't work here. Do any of the other Java DOM models make this easier? Or is there a way to do this in JDOM?