I've written an iterator over an `XMLNode`:

[https://hg.sr.ht/~sschwarzer/vppdiff/browse/default/src/vppdiff/cleanxmi.nim#L46](https://hg.sr.ht/~sschwarzer/vppdiff/browse/default/src/vppdiff/cleanxmi.nim#L46)

Internally the iterator uses a stack.

Iterator features:

  * You can modify the tree while iterating over it. For example, if you delete 
a child node, the iterator doesn't yield _its_ child nodes.
  * For each iteration, the iterator gives you parent node, child index and 
child node in a `NodeDescription` object, so you can delete the child node with 
`parent_node.delete(child_index)`.
  * The iterator goes from higher to lower child indices, so deleting child 
nodes doesn't shift the indices for the remaining child nodes in subsequent 
iterations.



I suspect the implementation is more complicated than it has to be, but this 
code is what I've been able to come up with. ;-)

Reply via email to