473,385 Members | 1,856 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,385 software developers and data experts.

how to clone a DOM document?

Hi,

I am trying to figure out how to make a complete copy of a DOM document. I
am using xerces but vanilla DOM would obviously be the best solution. The
nearest I have got is something like:

Document newDoc = new DocumentImpl();

newDoc.appendChild(newDoc.importNode(oldDoc.getDoc umentElement(),true));

but I presume this won't do namespace declarations, processing instructions,
the <?xml> declaration at the front etc etc.

I would have thought this would be a FAQ but I can't find anything obvious
anywhere.

many thanks

Andy

Jul 20 '05 #1
2 6586
Andy Fish wrote:
Hi,

I am trying to figure out how to make a complete copy of a DOM
document. I am using xerces but vanilla DOM would obviously be the
best solution. The nearest I have got is something like:

Document newDoc = new DocumentImpl();

newDoc.appendChild(newDoc.importNode(oldDoc.getDoc umentElement(),true));
but I presume this won't do namespace declarations, processing
instructions, the <?xml> declaration at the front etc etc.


Try something like:

newDoc = oldDoc.cloneNode(true);

Jul 20 '05 #2
Hey thanks Rolf, I must admit I'm kinda surprised that worked, but it
definitely worked for me.

Normally calling clone on a node returns somethng owned by the same document
as the original node, so I didn't think it would even be supported on a
document.

I notice that the javadoc for org.w3c.dom does not mention cloning a
document as a special case, but the w3c core specification says cloning a
document is implementation specific.

Andy
"Rolf Magnus" <ra******@t-online.de> wrote in message
news:c8*************@news.t-online.com...
Andy Fish wrote:
Hi,

I am trying to figure out how to make a complete copy of a DOM
document. I am using xerces but vanilla DOM would obviously be the
best solution. The nearest I have got is something like:

Document newDoc = new DocumentImpl();

newDoc.appendChild(newDoc.importNode(oldDoc.getDoc umentElement(),true));

but I presume this won't do namespace declarations, processing
instructions, the <?xml> declaration at the front etc etc.


Try something like:

newDoc = oldDoc.cloneNode(true);

Jul 20 '05 #3

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

Similar topics

2
by: ricky | last post by:
i have this xml document: <order> <item occur="unbounded"> <ref>122</ref> <name>bla bla</name> </item> <item occur="unbounded"> <ref>122</ref> <name>bla bla</name> </item>
4
by: Mike | last post by:
I am writing a post-processor for an existing XML document (that I have no control over), this entails a lot of inserting and deleting of nodes. I don't want to have to hard code the...
2
by: Donal McWeeney | last post by:
Hi, I think I may have a slight encoding problem with what I am doing. I have a test console app that takes an xml document and splits it into a number of smaller xml documents. First thing...
0
by: see_bees | last post by:
I am running Office 2000, and would like to create a deep clone of a word document object. 1. There is no clone function for the document class. 2. I can't get reflection to give me a list of...
6
by: J Williams | last post by:
I'm using axWebBrowser control and HTML DOM in a VB .NET Windows application to create a new HTML document by cloning nodes. The function below is called from the axWebBrowser1_DocumentComplete...
14
by: Alf P. Steinbach | last post by:
Not yet perfect, but: http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01.pdf http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01_examples.zip To access the table of...
1
by: jaktharkhan | last post by:
Hi, I really really need help in trying to figure out how can I do a CloneNode on an Iframe where the cloned IFRAME clones with all its contents?. Basically what I am doing is dynamically building...
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...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.