Replacing an XML element?

Max Erickson maxerickson at
Tue Sep 20 15:59:58 CEST 2005

Nick Vargish <nav+posts at> wrote in
news:87wtlbdfo4.fsf at localhost.localdomain: 

> I've been trying to figure out how to do something that seems
> relatively simple, but it's just not coming together for me. I'm
> hoping someone will deign to give me a little insight here.
> The problem: We have XML documents that use a custom table format
> that was designed primarily for typesetting documents. It's a
> column-first oriented scheme, and now we need a way to convert
> these table elements to HTML style row-first tables.
> I would like to be able to do something like this:
> doc = xml.dom.minidom.parse(input)
> for table in doc.getElementsByTagName('COLTABLE'):
>     newtable = coltable_to_rowtable(table)
>     ## this is what I can't figure out
>     doc.replace(table, newtable)
> output.write(doc.toxml('utf-8'))
> I'm pretty sure I'm missing something obvious, but haven't been
> able to find any examples. 
> Someone please whack me with a cluestick,
> Nick

table.parentNode.replaceChild(newtable, table)

More information about the Python-list mailing list