diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2011-11-18 15:34:26 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2011-11-18 15:34:26 (GMT) |
commit | 8008f2aba0c063a882c33ebd4b39a5a560deb8c0 (patch) | |
tree | e40e0b93e6dac9b1c2b5efa5769226884caab0db /Lib/xml/dom | |
parent | e62aad3073c6fe329d8cd67dda21199c67630ed5 (diff) | |
download | cpython-8008f2aba0c063a882c33ebd4b39a5a560deb8c0.zip cpython-8008f2aba0c063a882c33ebd4b39a5a560deb8c0.tar.gz cpython-8008f2aba0c063a882c33ebd4b39a5a560deb8c0.tar.bz2 |
#4147: minidom's toprettyxml no longer adds whitespace around a text node when it is the only child of an element. Initial patch by Dan Kenigsberg.
Diffstat (limited to 'Lib/xml/dom')
-rw-r--r-- | Lib/xml/dom/minidom.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/Lib/xml/dom/minidom.py b/Lib/xml/dom/minidom.py index 386494d..f23ad05 100644 --- a/Lib/xml/dom/minidom.py +++ b/Lib/xml/dom/minidom.py @@ -837,11 +837,15 @@ class Element(Node): writer.write("\"") if self.childNodes: writer.write(">") - if self.childNodes[0].nodeType != Node.TEXT_NODE: + if (len(self.childNodes) == 1 and + self.childNodes[0].nodeType == Node.TEXT_NODE): + self.childNodes[0].writexml(writer, '', '', '') + else: writer.write(newl) - for node in self.childNodes: - node.writexml(writer,indent+addindent,addindent,newl) - writer.write("%s</%s>%s" % (indent,self.tagName,newl)) + for node in self.childNodes: + node.writexml(writer, indent+addindent, addindent, newl) + writer.write(indent) + writer.write("</%s>%s" % (self.tagName, newl)) else: writer.write("/>%s"%(newl)) @@ -1063,7 +1067,7 @@ class Text(CharacterData): return newText def writexml(self, writer, indent="", addindent="", newl=""): - _write_data(writer, self.data) + _write_data(writer, "%s%s%s" % (indent, self.data, newl)) # DOM Level 3 (WD 9 April 2002) |