help with recursive whitespace filter in

Scott David Daniels Scott.Daniels at Acm.Org
Sun May 10 13:53:02 EDT 2009


Rustom Mody wrote:
> I am trying to write a recursive filter to remove whitespace-only
> nodes for minidom.
> The code is below.
> 
> Strangely it deletes some whitespace nodes and leaves some.
> If I keep calling it -- like so: fws(fws(fws(doc)))  then at some
> stage all the ws nodes disappear
> 
> Does anybody have a clue?

Yup, don't stand on the limb you are sawing off.

> def fws(ele):
...
>    for c in ele.childNodes:
>         if isWsNode(c):
>             ele.removeChild(c)
...
At the very least:
      for c in reversed(ele.childNodes):
           if isWsNode(c):
               ele.removeChild(c)

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list