[issue3075] make minidom.toxml() encoding argument useful
Mark Lawrence
report at bugs.python.org
Mon Jul 26 15:03:57 CEST 2010
Mark Lawrence <breamoreboy at yahoo.co.uk> added the comment:
This is how toprettyxml looks in 3.1/2 which seems to meet the OP's need, I'll close in a few days time unless someone objects.
def toprettyxml(self, indent="\t", newl="\n", encoding=None):
# indent = the indentation string to prepend, per level
# newl = the newline string to append
use_encoding = "utf-8" if encoding is None else encoding
writer = codecs.getwriter(use_encoding)(io.BytesIO())
if self.nodeType == Node.DOCUMENT_NODE:
# Can pass encoding only to document, to put it into XML header
self.writexml(writer, "", indent, newl, encoding)
else:
self.writexml(writer, "", indent, newl)
if encoding is None:
return writer.stream.getvalue().decode(use_encoding)
else:
return writer.stream.getvalue()
----------
nosy: +BreamoreBoy
status: open -> pending
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3075>
_______________________________________
More information about the Python-bugs-list
mailing list