[XML-SIG] copy node to new dom

Michael Mell mike@nthwave.net
Thu, 25 Oct 2001 09:47:44 -0700


Hi, 
I want to use xml.dom.minidom to parse a file, extract the document
element and then duplicate that element in a second dom. Ideally, these
four lines would do the job:
	srcDom  = xml.dom.minidom.parse(f1)
	destDom  = xml.dom.minidom.parse(f2)
	srcElement = srcDom.getElementsByTagName('myElement')[0]

	destDom.documentElement.appendChild(srcElement)
The last line fails, it seems, because the srcElement is meaningless in
the destDom.

The only workable method I came up with was to extract all the data from
srcElement, build a new destElement, and then append the destElement to
the destDom:
	srcDom  = xml.dom.minidom.parse(f1)
	destDom  = xml.dom.minidom.parse(f2)
	srcElement = srcDom.getElementsByTagName('myElement')[0]

	destElement = destDom.createElement('myElement')
	srcItem = srcElement.getElementsByTagName('item')[0]
	desElement.setAttribute('value', srcItem.getAttribute('value'))
	destDom.documentElement.appendChild(destElement)
The last four lines need to be repeated for each and every atribute of
each child element.

Is there a more efficient method?

thanks.
-- 
Choice links to sensible thinking:
http://www.nthwave.net:81/warAndSense/index.html

mike@nthwave.net 
llemekim         YahooIM 
415.455.8812     voice
419.735.1167     fax