You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
xml.dom.minidom.Element.cloneNode fails with AttributeError #49101
It seems impossible to clone an Element created without a document:
>>> Element('foo').cloneNode(False)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/xml/dom/minidom.py", line 211, in cloneNode
return _clone_node(self, deep, self.ownerDocument or self)
File "/usr/lib/python2.5/xml/dom/minidom.py", line 1814, in _clone_node
if node.ownerDocument.isSameNode(newOwnerDocument):
AttributeError: 'NoneType' object has no attribute 'isSameNode'
The documentation claims that cloneNode was fixed for releases
"subsequent" to 2.0, but this doesn't appear to be true.
A similar issue occurs when attempting to import a node into a document
(something I tried as a work-around for this failure):
>>> d.importNode(e, False)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/xml/dom/minidom.py", line 1737, in importNode
return _clone_node(node, deep, self)
File "/usr/lib/python2.5/xml/dom/minidom.py", line 1814, in _clone_node
if node.ownerDocument.isSameNode(newOwnerDocument):
AttributeError: 'NoneType' object has no attribute 'isSameNode'
15290 was closed as invalid, and the submitter was told that the
code should be changed to not rely on creating elements outside
of the document interface.
I encountered the same problem when trying to port Twisted to Python 3.
Thanks for your detective work, Craig. MvL is correct that those classes should be created via a Document object. I'm marking bpo-15290 as a duplicate of this.
Note that we can reopen this if you'd like to propose a documentation patch or PR to make the current docs clearer. Thanks!
Activity
exarkun commentedon Jan 5, 2009
It seems impossible to clone an Element created without a document:
>>> Element('foo').cloneNode(False) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.5/xml/dom/minidom.py", line 211, in cloneNode return _clone_node(self, deep, self.ownerDocument or self) File "/usr/lib/python2.5/xml/dom/minidom.py", line 1814, in _clone_node if node.ownerDocument.isSameNode(newOwnerDocument): AttributeError: 'NoneType' object has no attribute 'isSameNode'The documentation claims that cloneNode was fixed for releases
"subsequent" to 2.0, but this doesn't appear to be true.
http://docs.python.org/library/xml.dom.minidom.html#xml.dom.minidom.Node.cloneNode
A similar issue occurs when attempting to import a node into a document
(something I tried as a work-around for this failure):
>>> d.importNode(e, False) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.5/xml/dom/minidom.py", line 1737, in importNode return _clone_node(node, deep, self) File "/usr/lib/python2.5/xml/dom/minidom.py", line 1814, in _clone_node if node.ownerDocument.isSameNode(newOwnerDocument): AttributeError: 'NoneType' object has no attribute 'isSameNode'BreamoreBoy commentedon Jul 8, 2010
Has this simply slipped under the radar?
AlexandreZani commentedon May 20, 2012
This patch allows the cloning of elements that do not have a document owner.
If a node does not have a document owner, a new document owner is created for the clone.
CraigRodrigues commentedon Mar 6, 2017
This looks like a duplicate of https://bugs.python.org/issue15290
15290 was closed as invalid, and the submitter was told that the
code should be changed to not rely on creating elements outside
of the document interface.
I encountered the same problem when trying to port Twisted to Python 3.
berkerpeksag commentedon Mar 15, 2017
Thanks for your detective work, Craig. MvL is correct that those classes should be created via a Document object. I'm marking bpo-15290 as a duplicate of this.
Note that we can reopen this if you'd like to propose a documentation patch or PR to make the current docs clearer. Thanks!