diff -r 6bd6cc7f2c8d Lib/test/test_minidom.py --- a/Lib/test/test_minidom.py Sun Oct 02 01:08:37 2011 +0200 +++ b/Lib/test/test_minidom.py Sun Oct 02 13:53:11 2011 +0200 @@ -467,12 +467,12 @@ dom.unlink() self.confirm(domstr == str.replace("\n", "\r\n")) - def test_toPrettyXML_perserves_content_of_text_node(self): - str = 'B' - dom = parseString(str) - dom2 = parseString(dom.toprettyxml()) - self.assertEqual(dom.childNodes[0].childNodes[0].toxml(), - dom2.childNodes[0].childNodes[0].toxml()) + def test_toPrettyXML_preserves_content_of_text_node(self): + for str in ('A', 'C'): + dom = parseString(str) + dom2 = parseString(dom.toprettyxml()) + self.assertEqual(dom.getElementsByTagName('B')[0].childNodes[0].toxml(), + dom2.getElementsByTagName('B')[0].childNodes[0].toxml()) def testProcessingInstruction(self): dom = parseString('') diff -r 6bd6cc7f2c8d Lib/xml/dom/minidom.py --- a/Lib/xml/dom/minidom.py Sun Oct 02 01:08:37 2011 +0200 +++ b/Lib/xml/dom/minidom.py Sun Oct 02 13:53:11 2011 +0200 @@ -837,11 +837,16 @@ writer.write("\"") if self.childNodes: writer.write(">") - if self.childNodes[0].nodeType != Node.TEXT_NODE: + if all(map(lambda n: n.nodeType == Node.TEXT_NODE, + self.childNodes)): + for node in self.childNodes: + node.writexml(writer, '', '', '') + else: writer.write(newl) - for node in self.childNodes: - node.writexml(writer,indent+addindent,addindent,newl) - writer.write("%s%s" % (indent,self.tagName,newl)) + for node in self.childNodes: + node.writexml(writer, indent+addindent, addindent, newl) + writer.write(indent) + writer.write("%s" % (self.tagName, newl)) else: writer.write("/>%s"%(newl)) @@ -1063,7 +1068,7 @@ 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)