# HG changeset patch # User Dan Kenigsberg # Date 1317492169 -10800 # Node ID a9a87f0e7c509ec6768379c08a0cf56f43d71b4a # Parent b0ef6a5a6dccab0089d287bf6b9bcb8132bdbd0d xml.dom.minidom toprettyxml: omit whitespace for Text nodes  http://bugs.python.org/issue4147  This patch was very lightly tested, but I think it is nicer than the former one, as Text.writexml() should better know not to wrap its data with whitespace. Ever.  diff -r b0ef6a5a6dcc -r a9a87f0e7c50 Lib/test/test_minidom.py --- a/Lib/test/test_minidom.py Fri Sep 30 08:46:25 2011 +0300 +++ b/Lib/test/test_minidom.py Sat Oct 01 21:02:49 2011 +0300 @@ -467,6 +467,13 @@ 467  dom.unlink() 467  dom.unlink() 468  self.confirm(domstr == str.replace("\n", "\r\n")) 468  self.confirm(domstr == str.replace("\n", "\r\n"))   469    470  def testPrettyTextNode(self):   471  str = 'B'   472  dom = parseString(str)   473  dom2 = parseString(dom.toprettyxml())   474  self.confirm(dom.childNodes[0].childNodes[0].toxml()==   475  dom2.childNodes[0].childNodes[0].toxml()) 469  476  470  def testProcessingInstruction(self): 477  def testProcessingInstruction(self): 471  dom = parseString('') 478  dom = parseString('') 472  pi = dom.documentElement.firstChild 479  pi = dom.documentElement.firstChild diff -r b0ef6a5a6dcc -r a9a87f0e7c50 Lib/xml/dom/minidom.py --- a/Lib/xml/dom/minidom.py Fri Sep 30 08:46:25 2011 +0300 +++ b/Lib/xml/dom/minidom.py Sat Oct 01 21:02:49 2011 +0300 @@ -836,7 +836,9 @@  836  _write_data(writer, attrs[a_name].value)  836  _write_data(writer, attrs[a_name].value)  837  writer.write("\"")  837  writer.write("\"")  838  if self.childNodes:  838  if self.childNodes:  839  writer.write(">%s"%(newl))  839  writer.write(">")    840  if self.childNodes[0].nodeType != Node.TEXT_NODE:    841  writer.write(newl)  840  for node in self.childNodes:  842  for node in self.childNodes:  841  node.writexml(writer,indent+addindent,addindent,newl)  843  node.writexml(writer,indent+addindent,addindent,newl)  842  writer.write("%s%s" % (indent,self.tagName,newl))  844  writer.write("%s%s" % (indent,self.tagName,newl)) @@ -1061,7 +1063,7 @@ 1061  return newText 1063  return newText 1062  1064  1063  def writexml(self, writer, indent="", addindent="", newl=""): 1065  def writexml(self, writer, indent="", addindent="", newl=""): 1064  _write_data(writer, "%s%s%s"%(indent, self.data, newl)) 1066  _write_data(writer, self.data) 1065  1067  1066  # DOM Level 3 (WD 9 April 2002) 1068  # DOM Level 3 (WD 9 April 2002) 1067  1069