This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
标题: xml.dom.minidom.Element.cloneNode fails with AttributeError
类型: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
状态: closed Resolution: not a bug
Dependencies: 后续:
分配给: 抄送列表: Alexandre.Zani, Claudiu.Popa, Craig Rodrigues, berker.peksag, exarkun, loewis
优先级: normal 关键字: needs review, patch

Created on 2009-01-05 22:00 by exarkun, last changed 2022-04-11 14:56 by admin. This issue is now closed.

文件
文件名 上传时间 Description 编辑
orphan_node_clone.patch Alexandre.Zani, 2012-05-20 19:19 Patch fix review
Messages (5)
msg79203 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) 日期: 2009-01-05 22:00
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'
msg109606 - (view) Author: Mark Lawrence (BreamoreBoy) * 日期: 2010-07-08 21:17
Has this simply slipped under the radar?
msg161225 - (view) Author: Alexandre Zani (Alexandre.Zani) 日期: 2012-05-20 19:19
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.
msg289058 - (view) Author: Craig Rodrigues (Craig Rodrigues) 日期: 2017-03-06 02:27
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.
msg289663 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) 日期: 2017-03-15 10:38
Thanks for your detective work, Craig. MvL is correct that those classes should be created via a Document object. I'm marking issue 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!
历史
日期 用户 动作 参数
2022-04-11 14:56:43admin修改github: 49101
2017-03-15 10:38:34berker.peksag修改状态: open -> closed

抄送: + berker.peksag
消息: + msg289663

resolution: not a bug
stage: patch review -> resolved
2017-03-15 10:38:12berker.peksag链接issue15290 superseder
2017-03-06 02:27:20Craig Rodrigues修改抄送: + Craig Rodrigues
消息: + msg289058
2015-03-07 19:12:06Claudiu.Popa修改抄送: + Claudiu.Popa

versions: + Python 3.5, - Python 2.7, Python 3.2, Python 3.3
2014-02-03 19:11:54BreamoreBoy修改抄送: - BreamoreBoy
2012-05-21 03:36:54eric.araujo修改keywords: + needs review
stage: needs patch -> patch review
versions: + Python 3.3, - Python 3.1
2012-05-20 19:19:29Alexandre.Zani修改文件: + orphan_node_clone.patch
keywords: + patch
消息: + msg161225
2011-05-03 16:38:06Alexandre.Zani修改抄送: + Alexandre.Zani
2010-07-08 21:17:04BreamoreBoy修改versions: + Python 3.1, Python 2.7, Python 3.2
抄送: + loewis, BreamoreBoy

消息: + msg109606

stage: needs patch
2009-01-05 22:00:10exarkun创建