Replacing an XML element?

Nick Vargish nav+posts at bandersnatch.org
Tue Sep 20 09:36:43 EDT 2005


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

-- 
#include<stdio.h>    /* sigmask (sig.c) 20041028 PUBLIC DOMAIN */
int main(c,v)char *v;{return !c?putchar(*   /* cc -o sig sig.c */
v-1)&&main(0,v+1):main(0,"Ojdl!Wbshjti!=ojdlAwbshjti/psh?\v\1");}



More information about the Python-list mailing list