xml : remove a node with dom

Diez B. Roggisch deets at web.de
Thu Oct 28 13:47:21 CEST 2010

alain walter <alain.serge.walter at gmail.com> writes:

> 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

If you post code, make an attempt for it to be runnable. I had to fix
numerous simple errors to make it run & actually solve your problem.

from xml.dom.minidom import parse,parseString
from xml.dom import Node

<aixm:VORTimeSlice xmlns:aixm="aixm" xmlns:gml="gml" gml:id="ABB">
      <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>

dom = parseString(toxml)

def ApplicationWhitespaceRemoving(ele) :
   for c in ele.childNodes:
      if c.nodeType == c.TEXT_NODE:
         if c.nodeValue == "xxx_toremove_xxx":
             parent = c.parentNode
      elif c.nodeType == ele.ELEMENT_NODE:


print dom.toxml()



More information about the Python-list mailing list