473,388 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Replacing an XML element?

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!=ojdlAwbshjt i/psh?\v\1");}
Sep 20 '05 #1
2 1553
Nick Vargish <na*******@bandersnatch.org> wrote in
news:87************@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)
Sep 20 '05 #2
Max Erickson <ma*********@gmail.com> writes:
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

--
#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!=ojdlAwbshjt i/psh?\v\1");}
Sep 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: John Livermore | last post by:
From javascript in IE, I have a need to hijack the onclick event for an element and replace it dynamically with my own. I have tried the following... control.onclick = 'myHandler();'; but...
1
by: Søren Schimkat | last post by:
Hi everyone I´m having some problems with replacing one form with another. The first problem is the the replace function only works once - and the second problem is that the thml code dosn´t get...
11
by: Peter Foti | last post by:
Hi all, I have a form that contains a 2 column table. In the left column is the description for a particular input (ie - "First Name", "Last Name", "Phone Number", etc.). In the right column...
6
by: Peter Foti | last post by:
I have seen lots of examples where some HTML text is replaced with a background image using CSS. For example, replacing the text of an <h1> with a graphical logo, like so: CSS: h1 span {...
2
by: André | last post by:
I've started using elementtree and don't understand how to use it to manipulate and replace nodes. I know how to do this using a simple, but inefficient parser I wrote, but I'd rather learn to use...
20
by: AndyZa | last post by:
Is the following html valid? <p><hr width="50%"></p> Or would the following be more "technically correct"? <p> <hr width="50%"> Do I require the closing </p> tag?
6
by: tentstitcher | last post by:
Hi all: I have a source xml document with an element of type string. This element contains something like the following: <stringData> &lt;Header&gt; &lt;Body&gt; </stringData> I would like to apply an...
7
by: Daniel Kabs | last post by:
Hi there, for a long time I've been using tables to layout elements on a web page. Example: Say we have a 2x2 table and I'd like to put text (left aligned) and buttons (right aligned) in the...
29
by: Nick | last post by:
I've seen a few frameworks use the following: function $(id) { return document.getElementById(id); } Then to use: $('something').innerHTML = 'blah'; I'm just trying to roll this out to my...
1
by: TamusJRoyce | last post by:
I have xsl code which I was hoping could be used to replace one specific tag from an xhtml document and output another xhtml document. xsl has phenomenal potential in data replacing, but coming...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.