[XML-SIG] copy node to new dom

Mike Hostetler thehaas@matrix.binary.net
Thu, 25 Oct 2001 13:12:37 -0500


On Thu, October 25, 2001 at 09:47:44AM -0700, Michael Mell wrote:
> 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)

I used the Sax reader from PyXML and just did:
   destDom.importNode(srcElement,deep=1)  # copies all child nodes as well
   destDom.documentElement.appendChild(srcElement)

However, minidom doesn't have an 'importNode" method.  I've found minidom
is not up to the task when doing advanced things (and taking part of a
DOM tree and putting it into another DOM tree *is* advanced).  I hate to
sound elitest, but change to PyXML -- it will make things easier.

Mike
--