# so that ET preserves your namespaces<br />ET._namespace_map[&quot;http://www.w3.org/2001/XMLSchema&quot;] = &#39;xs&#39;<br /><br /># open your file explicitly specifying the correct mode<br />f = open(&#39;testing.xml&#39;, &#39;w&#39;)<br />xml_tree.write(f, encoding=&#39;UTF-8&#39;)<br />f.close()