title: Write xml utf-8 file with utf-8 data with ElementTree
body: <p>I'm trying to write an xml file with utf-8 encoded data using ElementTree like this:</p>
  
  <pre><code>#!/usr/bin/python                                                                       
  # -*- coding: utf-8 -*-                                                                   
  
  import xml.etree.ElementTree as ET
  import codecs
  
  testtag = ET.Element('unicodetag')
  testtag.text = u'Töreboda' #The o is really &amp;#246; (o with two dots over). No idea why SO dont display this
  expfile = codecs.open('testunicode.xml',"w","utf-8-sig")
  ET.ElementTree(testtag).write(expfile,encoding="UTF-8",xml_declaration=True)
  expfile.close()
  </code></pre>
  
  <p>This blows up with the error</p>
  
  <pre><code>Traceback (most recent call last):
    File "unicodetest.py", line 10, in &lt;module&gt;
      ET.ElementTree(testtag).write(expfile,encoding="UTF-8",xml_declaration=True)
    File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 815, in write
      serialize(write, self._root, encoding, qnames, namespaces)    
    File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 932, in _serialize_xml
      write(_escape_cdata(text, encoding))
    File "/usr/lib/python2.7/codecs.py", line 691, in write
      return self.writer.write(data)
    File "/usr/lib/python2.7/codecs.py", line 351, in write
      data, consumed = self.encode(object, self.errors)
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1: ordinal not in range(128)
  </code></pre>
  
  <p>Using the "us-ascii" encoding instead works fine, but don't preserve the unicode characters in the data. What is happening?</p>