 <p>I just used a simple regex. Of course, my answer is in python 2.7 so this may not work for you, depending on the version of python you are using.</p> <pre><code>input = '' with open('input.xml', 'r') as input_file: input_file = open('input.xml', 'r') input = input_file.read() import re output = re.sub('\n\s*([^&lt;&gt; ]+)\s*\n\s*', '\\1', input, flags=re.MULTILINE) with open('output.xml', 'w') as output_file: output_file.write(output) </code></pre> <p>Here's a working repl: <a href="http://repl.it/1SG/3" rel="nofollow">http://repl.it/1SG/3</a></p> <p><strong>EDIT</strong></p> <p>This will not work if your values contain greater than or less than signs. I'm not sure how XML works entirely but it may not even allow those characters as values anyway.</p>