开发者

Writing to a new Xml file using Python Error Message?

What is this error message ?

My code

#!/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

Error is

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 

Is it because it is not able to able to find the path of my python?

Thanks in advance


You forgot to import xml.dom.minidom to import the XML minidom module.

>>> 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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜