[XML-SIG] Help with removeChild()

Michael Hammill mike@pdc.kth.se
Thu, 10 May 2001 16:03:40 +0200


Dear Thomas,

Your solution below works great!   I have discovered something else quite 
instructive (at least to me).  When I first saw your solution, I thought 
"oh, I've tried that already".  Silly of me.  What I had tried was not 
exactly the same, but seemingly close.  I had set children = 
node.childNodes *without* the final '[:]'.  In testing the solution below, 
I found that if the [:] is left out, the result is the same as I got before 
(an incorrect trimming); however, with the [:] it works fine.  I'm sorry if 
this is a newbe kind of confusion.  I had always thought "list" was 
equivalent to "list[:]", but apparently not.

Thank you again!
Mike

[...]
>  Try this:
>
>  def trim_dom_more(node):
>      if node.hasChildNodes():
>          children=node.childNodes[:]
>          for child in children:
>              trim_dom_more(child)
>
>Now you are iterating through a static copy of the list.  It wouldn't work
>if the child nodes could get changed by another thread, but I don't suppose
>that's going to happen here.
[...]