title: Python: flatten an XML document (remove newlines)
body: <p>Python newbie here.</p>
  
  <p>I want to flatten XML documents. For example, I want to convert this:</p>
  
  <pre><code>&lt;Document&gt;
      Hello, World
  &lt;/Document&gt;
  </code></pre>
  
  <p>to this:</p>
  
  <pre><code>&lt;Document&gt;    Hello, World&lt;/Document&gt;
  </code></pre>
  
  <p>I wrote a Python program, flatten.py, to do the flattening:</p>
  
  <pre><code>import sys
  import stdio
  
  s = ''
  while True:
     t = sys.stdin.readline()
     if not t:
        break
     s = s + t
  
  stdio.write(s.rstrip('\r\n'))
  </code></pre>
  
  <p>I created an exe for flatten.py. Then I opened a DOS window and typed:</p>
  
  <pre><code>type input.xml | flatten
  </code></pre>
  
  <p>(input.xml is the XML shown above)</p>
  
  <p>Here is the output:</p>
  
  <pre><code>&lt;Document&gt;
      Hello, World
  &lt;/Document&gt;
  </code></pre>
  
  <p>Sadly, the XML is not flattened. What am I doing wrong please? </p>