使用Python错误消息写入新的Xml文件?

时间:2011-05-28 07:27:13

标签: python cgi

这是什么错误信息?

我的代码

#!/usr/bin/python
from xml.dom.minidom import Document

def CreateXml(nameSpace, rootElementName):
    xmlDoc = xml.dom.minidom.Document()
    xmlRootElement = doc.createElementNS(nameSpace, rootElementName)
    xmlDoc.appendChild(xmlRootElement)

    return xmlDoc

错误是

File "/home/users/web/b2896/moo.something/cgi-bin/py/sbmain/main.py", line 27, in initialize 
xmlDoc = py.sbxml.XmlDocumentHandler.CreateXml(_GUESTNAMESPACE, 'guest') 
File "/home/users/web/b2896/moo.something/cgi-bin/py/sbxml/XmlDocumentHandler.py", line 6, in CreateXml 
xmlDoc = xml.dom.minidom.Document() 
NameError: global name 'xml 

是因为它无法找到我的python的路径吗?

提前致谢

1 个答案:

答案 0 :(得分:0)

您忘记import xml.dom.minidom导入 XML minidom 模块。

>>> xml.dom.minidom.Document()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'xml' is not defined
>>> import xml.dom.minidom
>>> xml.dom.minidom.Document()
<xml.dom.minidom.Document instance at 0x7f73ae601a28>