modifying XML documents

Alex Martelli aleax at aleax.it
Sat May 3 10:56:16 EDT 2003


Alessio Pace wrote:

> Hi,
> I use xml.minidom to parse XML documents, and it works fine.
> I am now trying to actually modify the XML document that I read.
> All I need, at the moment, is to make a substitution of a subtree rooted
> at one element of the xml document with a new subtree (whose element name
> and structure obviously has to reflect the dtd declarations as the element
> to be substituted). I tried simply to substitute the NodeList with the new
> one, but I saw that attribute is read-only and while I see method to
> create elements, I don't see anything to *remove* something.. :-( How
> should I do so?

I think you're looking for the removeChild and/or replaceChild methods
of the Node class -- all the components of an XML document are instances
of some subclass or other of that Node class.  See:

http://www.python.org/doc/current/lib/dom-node-objects.html

and nearby parts of the standard Python docs.


Alex





More information about the Python-list mailing list