[XML-SIG] Copying an element from one DOM to another

Douglas Bates bates@stat.wisc.edu
19 Feb 2002 13:49:41 -0600


I have a series of XML files whose contents I want to collect into a
container element in a single file.  I plan to use the xml.dom
facilities to open up each of the input files, create a dom, determine
the part that I want to copy into the output file and somehow copy
it.  I'm stuck on the "somehow copy it" part.  I had hoped to use
code like

output.documentElement.appendNode(input.elementOfInterest.cloneNode(1))

but that fails telling me
xml.dom.WrongDocumentErr: Node is from a different document

I could write a function that walked the tree of the source node and
created the copy in the target one element at a time but I have the
feeling that I must be missing something obvious.  Am I?