<?xml version="1.0" encoding="utf-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Fixing minidom.toprettyxml&#8217;s Silly Whitespace</title>
	<atom:link href="http://ronrothman.com/public/leftbraned/xml-dom-minidom-toprettyxml-and-silly-whitespace/feed/" rel="self" type="application/rss+xml" />
	<link>http://ronrothman.com/public/leftbraned/xml-dom-minidom-toprettyxml-and-silly-whitespace/</link>
	<description>go. figure. «</description>
	<pubDate>Wed, 19 Nov 2008 22:42:37 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: Thomas Pluempe</title>
		<link>http://ronrothman.com/public/leftbraned/xml-dom-minidom-toprettyxml-and-silly-whitespace/#comment-38220</link>
		<dc:creator>Thomas Pluempe</dc:creator>
		<pubDate>Mon, 03 Nov 2008 16:59:37 +0000</pubDate>
		<guid isPermaLink="false">http://ronrothman.com/public/leftbraned/?p=252#comment-38220</guid>
		<description>Thanks for the fixed_writexml fix, made my day. I'm using this successfully with Python 2.6.

However, there's a tiny bug there: In line 20, that's the "writer.write("&#60;%s"%(newl))" line, the less than sign should be a greater than sign.

Only with this fix does it generate valid XML.

&lt;i&gt;Response from Ron: Thomas, thanks for pointing out the typo!  I've fixed it in the post.  Much appreciated,
Ron&lt;/i&gt;</description>
		<content:encoded><![CDATA[<p>Thanks for the fixed_writexml fix, made my day. I&#8217;m using this successfully with Python 2.6.</p>
<p>However, there&#8217;s a tiny bug there: In line 20, that&#8217;s the &#8220;writer.write(&#8221;&lt;%s&#8221;%(newl))&#8221; line, the less than sign should be a greater than sign.</p>
<p>Only with this fix does it generate valid XML.</p>
<p><i>Response from Ron: Thomas, thanks for pointing out the typo!  I&#8217;ve fixed it in the post.  Much appreciated,<br />
Ron</i></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gmolleda</title>
		<link>http://ronrothman.com/public/leftbraned/xml-dom-minidom-toprettyxml-and-silly-whitespace/#comment-37581</link>
		<dc:creator>gmolleda</dc:creator>
		<pubDate>Wed, 09 Jul 2008 11:39:40 +0000</pubDate>
		<guid isPermaLink="false">http://ronrothman.com/public/leftbraned/?p=252#comment-37581</guid>
		<description>Hi, I have fixed other problem [in minidom]:
When you use the writexml function for write a beautiful and readable file, and read the file, and other time use writexml function, then you could view a lot of ugly newline characters.

Adding a new conditional in the loop "for", we could remove the blank lines with only indent and newline characters

&lt;code&gt;
        for node in self.childNodes:
+	    if node.nodeType is not xml.dom.minidom.Node.TEXT_NODE: # 3:
+                node.writexml(writer,indent+addindent,addindent,newl)
-            #node.writexml(writer,indent+addindent,addindent,newl)
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Hi, I have fixed other problem [in minidom]:<br />
When you use the writexml function for write a beautiful and readable file, and read the file, and other time use writexml function, then you could view a lot of ugly newline characters.</p>
<p>Adding a new conditional in the loop &#8220;for&#8221;, we could remove the blank lines with only indent and newline characters</p>
<p><code><br />
        for node in self.childNodes:<br />
+	    if node.nodeType is not xml.dom.minidom.Node.TEXT_NODE: # 3:<br />
+                node.writexml(writer,indent+addindent,addindent,newl)<br />
-            #node.writexml(writer,indent+addindent,addindent,newl)<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gmolleda</title>
		<link>http://ronrothman.com/public/leftbraned/xml-dom-minidom-toprettyxml-and-silly-whitespace/#comment-37580</link>
		<dc:creator>gmolleda</dc:creator>
		<pubDate>Wed, 09 Jul 2008 09:08:56 +0000</pubDate>
		<guid isPermaLink="false">http://ronrothman.com/public/leftbraned/?p=252#comment-37580</guid>
		<description>Hi, if you add a conditional in loop for, the extra newline character is not added in next calls to function:
&lt;code&gt;
        writer.write("&#62;%s" % (newl))
        for node in self.childNodes:
+	    if node.nodeType is not xml.dom.minidom.Node.TEXT_NODE: # 3:
                node.writexml(writer,indent+addindent,addindent,newl)
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Hi, if you add a conditional in loop for, the extra newline character is not added in next calls to function:<br />
<code><br />
        writer.write("&gt;%s" % (newl))<br />
        for node in self.childNodes:<br />
+	    if node.nodeType is not xml.dom.minidom.Node.TEXT_NODE: # 3:<br />
                node.writexml(writer,indent+addindent,addindent,newl)<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ron</title>
		<link>http://ronrothman.com/public/leftbraned/xml-dom-minidom-toprettyxml-and-silly-whitespace/#comment-37579</link>
		<dc:creator>Ron</dc:creator>
		<pubDate>Wed, 09 Jul 2008 00:05:20 +0000</pubDate>
		<guid isPermaLink="false">http://ronrothman.com/public/leftbraned/?p=252#comment-37579</guid>
		<description>gmodella, thanks for your feedback.  You're right, the code as published wasn't working, because Wordpress converted my "" to html tag delimiters, instead of converting them to "&#38;lt;" and "&#38;gt;".  (Notice that it did the same thing in your comment; your 'write.write("%s%s"...' should have a , but Wordpress stripped them in your comment as well.)

I've fixed it manually, and now Wordpress is rendering it correctly.  Thank you for alerting me!</description>
		<content:encoded><![CDATA[<p>gmodella, thanks for your feedback.  You&#8217;re right, the code as published wasn&#8217;t working, because Wordpress converted my &#8220;&#8221; to html tag delimiters, instead of converting them to &#8220;&amp;lt;&#8221; and &#8220;&amp;gt;&#8221;.  (Notice that it did the same thing in your comment; your &#8216;write.write(&#8221;%s%s&#8221;&#8230;&#8217; should have a , but Wordpress stripped them in your comment as well.)</p>
<p>I&#8217;ve fixed it manually, and now Wordpress is rendering it correctly.  Thank you for alerting me!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gmolleda</title>
		<link>http://ronrothman.com/public/leftbraned/xml-dom-minidom-toprettyxml-and-silly-whitespace/#comment-37578</link>
		<dc:creator>gmolleda</dc:creator>
		<pubDate>Tue, 08 Jul 2008 17:03:20 +0000</pubDate>
		<guid isPermaLink="false">http://ronrothman.com/public/leftbraned/?p=252#comment-37578</guid>
		<description>I have found errors in fixed_writexml function:
1.- Errors in number %s into strings
2.- Errors in ending labels, the functions write label and not 

The correct is:

def fixed_writexml(self, writer, indent="", addindent="", newl=""):
    # indent = current indentation
    # addindent = indentation to add to higher levels
    # newl = newline string
    writer.write(indent+"")
            self.childNodes[0].writexml(writer, "", "", "" )
            writer.write("%s" % (self.tagName, newl))
            return
        writer.write("&#62;%s" % (newl))
        for node in self.childNodes:
            node.writexml(writer,indent+addindent,addindent,newl)
        writer.write("%s%s" % (indent,self.tagName,newl))
    else:
        writer.write("/&#62;%s"%(newl))


# replace minidom’s function with ours
xml.dom.minidom.Element.writexml = fixed_writexml</description>
		<content:encoded><![CDATA[<p>I have found errors in fixed_writexml function:<br />
1.- Errors in number %s into strings<br />
2.- Errors in ending labels, the functions write label and not </p>
<p>The correct is:</p>
<p>def fixed_writexml(self, writer, indent=&#8221;", addindent=&#8221;", newl=&#8221;"):<br />
    # indent = current indentation<br />
    # addindent = indentation to add to higher levels<br />
    # newl = newline string<br />
    writer.write(indent+&#8221;")<br />
            self.childNodes[0].writexml(writer, &#8220;&#8221;, &#8220;&#8221;, &#8220;&#8221; )<br />
            writer.write(&#8221;%s&#8221; % (self.tagName, newl))<br />
            return<br />
        writer.write(&#8221;&gt;%s&#8221; % (newl))<br />
        for node in self.childNodes:<br />
            node.writexml(writer,indent+addindent,addindent,newl)<br />
        writer.write(&#8221;%s%s&#8221; % (indent,self.tagName,newl))<br />
    else:<br />
        writer.write(&#8221;/&gt;%s&#8221;%(newl))</p>
<p># replace minidom’s function with ours<br />
xml.dom.minidom.Element.writexml = fixed_writexml</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ron</title>
		<link>http://ronrothman.com/public/leftbraned/xml-dom-minidom-toprettyxml-and-silly-whitespace/#comment-37538</link>
		<dc:creator>Ron</dc:creator>
		<pubDate>Sun, 15 Jun 2008 09:07:26 +0000</pubDate>
		<guid isPermaLink="false">http://ronrothman.com/public/leftbraned/?p=252#comment-37538</guid>
		<description>Yikes, I just came across a better solution on &lt;i&gt;comp.lang.python&lt;/i&gt;: use &lt;strong&gt;xml.dom.ext.PrettyPrint&lt;/strong&gt;.

I've updated the main post to reflect this option.  (See &lt;a href="#best-solution" rel="nofollow"&gt;#4&lt;/a&gt;.)</description>
		<content:encoded><![CDATA[<p>Yikes, I just came across a better solution on <i>comp.lang.python</i>: use <strong>xml.dom.ext.PrettyPrint</strong>.</p>
<p>I&#8217;ve updated the main post to reflect this option.  (See <a href="#best-solution" rel="nofollow">#4</a>.)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.828 seconds -->
