classification
Title: Empty ('') xmlns attribute is not properly handled by xml.dom.minidom
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: atamyrat, ezio.melotti
Priority: normal Keywords:

Created on 2011-05-12 21:11 by atamyrat, last changed 2011-05-13 08:02 by ezio.melotti.

Messages (1)
msg135867 - (view) Author: Atamurad Hezretkuliyev (atamyrat) Date: 2011-05-12 21:11
Parsing "<test xmlns=''></test>" with minidom and converting back to string raises an exception.

>>> import xml.dom.minidom
>>> xml.dom.minidom.parseString("<test xmlns=''></test>").toxml()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/dom/minidom.py", line 45, in toxml
    return self.toprettyxml("", "", encoding)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/dom/minidom.py", line 57, in toprettyxml
    self.writexml(writer, "", indent, newl, encoding)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/dom/minidom.py", line 1749, in writexml
    node.writexml(writer, indent, addindent, newl)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/dom/minidom.py", line 812, in writexml
    _write_data(writer, attrs[a_name].value)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/dom/minidom.py", line 301, in _write_data
    data = data.replace("&", "&amp;").replace("<", "&lt;")
AttributeError: 'NoneType' object has no attribute 'replace'
>>> 

Ii am not familiar with the XML spec so I've no idea if ignoring or accepting empty namespace is the right thing to do. If someone advices me on how it should be handled, I'd like to write a patch.
History
Date User Action Args
2011-05-13 08:02:24ezio.melottisetnosy: + ezio.melotti
2011-05-12 21:11:15atamyratcreate