天天看点

python xml dom_使用Python的xml.dom.minidom

我正在尝试使用Python的xml.dom.minidom,但出现以下错误:

>>> from xml.dom import minidom

>>> xdocument = minidom.Document()

>>> xrss = minidom.Element("rss")

>>> xdocument.appendChild(xrss)

>>> xchannel = minidom.Element("channel")

>>> xrss.appendChild(xchannel)

Traceback (most recent call last):

File "C:\Program Files\Wing IDE 3.2\src\debug\tserver\_sandbox.py", line 1, in ?

# Used internally for debug sandbox under external interpreter

File "c:\Python24\Lib\xml\dom\minidom.py", line 123, in appendChild

_clear_id_cache(self)

File "c:\Python24\Lib\xml\dom\minidom.py", line 1468, in _clear_id_cache

node.ownerDocument._id_cache.clear()

AttributeError: 'NoneType' object has no attribute '_id_cache'

>>>

有人知道为什么吗?

解决方法:

使用xdocument.createElement(‘name’)创建新元素.这是在DOM中执行此操作的标准方法.

标签:xml,python

来源: https://codeday.me/bug/20191210/2101882.html