Replacing an XML element?

N

Nick Vargish

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
 
M

Max Erickson

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)
 
N

Nick Vargish

Max Erickson said:
table.parentNode.replaceChild(newtable, table)

I knew it had to be something simple (but not as simple as I am,
apparently :^).

Thanks much, Max, you've saved the rest of my day.

Nick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,264
Messages
2,571,320
Members
48,004
Latest member
KelseyFors

Latest Threads

Top