2009-10-08 6 views
3
내가 파이썬의 xml.dom.minidom를 사용하려고 해요

을 사용하여, 나는 다음과 같은 오류 받고 있어요 :파이썬의 xml.dom.minidom

>>> from xml.dom import minidom 
>>> xdocument = minidom.Document() 
>>> xrss = minidom.Element("rss") 
>>> xdocument.appendChild(xrss) 
<DOM Element: rss at 0xc1d0f8> 
>>> 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' 
>>> 

사람이 어떤 생각 이유를 가지고 있습니까?

답변

3

xdocument.createElement('name')을 사용하여 새 요소를 만듭니다. 이것은 DOM에서이를 수행하는 표준 방법입니다.

0

xdocument.appendChild(xrss)xrss = xdocument.appendChild(xrss)으로 바꿉니다. docs에서 :

Node.appendChild(newChild) Add a new child node to this node at the end of the list of children, returning newChild. If the node was already in in the tree, it is removed first.

그래서 당신은 appendChild에서 반환 된 요소에 xrss를 할당해야합니다.