How can I copy a DOM Element form a existing Tree to a new Tree with minidom?
<p>I have to proceed a large XML file. I need a copy of the file, which contains specific Elements of the original file.
I tried to generate the new DOM-document like this</p>

<pre><code>import xml.dom.minidom as dom
xml = dom.parse("somefile.xml")
tree = dom.Document()
copy = dom.Element("xmlcopy")
tree.appendChild(copy)
header = xml.getElementsByTagName("header")[0]
tree.appendChild(header)
</code></pre>

<p>At this point I already get "AttributeError: ownerDocument".</p>

<pre><code>headercopy = header.cloneNode(True)
</code></pre>

<p>Didn't change anything. I'm new to python so I only know basics.
How can I copy Elements to the new Document?</p>

<p>Use <code>importNode</code>: <code>tree.appendChild(tree.ownerDocument.importNode(header, TRUE))</code>.</p>

python xml dom