xml : remove a node with dom

alain walter alain.serge.walter at gmail.com
Thu Oct 28 05:37:06 EDT 2010


Hello,
I have many difficulties to manipulate xml routines. I'm working with
python 2.4.4 and I cannot change to a more recent one, then I use dom
package, why not.
In the following code, I'm trying unsuccessfully to remove a
particular node. It seems to me that it should be basic, but it's
not.
Thanks for your help

toxml="<aixm:VORTimeSlice gml:id="ABB">
   <aixm:type>ABB</aixm:type>
      <aixm:designator>ABB</aixm:designator>
      <aixm:ElevatedPoint gml:id="ABB" srsDimension="2">
         <gml:pos srsDimension="2">-51.23 4.6501</gml:pos>
         <aixm:elevation uom="M">xxx_toremove_xxx</aixm:elevation>
      </aixm:ElevatedPoint>
</aixm:VORTimeSlice>"

from xml.dom.minidom import parse,parseString

dom = parseString(toxml)
self.ApplicationWhitespaceRemoving(dom)
print toxml

def ApplicationWhitespaceRemoving(self,ele) :
   from xml.dom import Node
   for c in ele.childNodes:
      if c.nodeType == c.TEXT_NODE:
         if c.nodeValue == "xxx_toremove_xxx":
            ???.removeChild(???)
      elif c.nodeType == ele.ELEMENT_NODE:
         self.ApplicationWhitespaceRemoving(c)



More information about the Python-list mailing list