title: parse xml with elementtree, custom sorting
body: <p>I want to parse xml file in utf-8 and sort it by some field. Soring is made by custom alphabet (s1 from sourcecode). History of question is here:
  <a href="https://stackoverflow.com/questions/10792241/sorting-of-list-containing-utf-8-charachters">sorting of list containing utf-8 charachters</a>.
  I've found how to sort xml <a href="http://effbot.org/zone/element-sort.htm" rel="nofollow noreferrer">here</a>. Sorting work correctly, the problem is with elementtree, I must admit that it doesn't work on python3</p>
  
  <p>Here is source code:</p>
  
  <pre><code>#!/usr/bin/env python
  # -*- coding: utf-8 -*-
  #import xml.etree.ElementTree as ET   # Python 2.5
  import elementtree.ElementTree as ET
  s1='aáàAâÂbBcCçÇdDeéEfFgGğĞhHiİîÎíīıIjJkKlLmMnNóoOöÖpPqQrRsSşŞtTuUûúÛüÜvVwWxXyYzZ'
  s2='11111122334455666aabbccddeeeeeeffgghhiijjkklllllmmnnooppqqrrsssssttuuvvwwxxyy'
  trans = str.maketrans(s1, s2)
  def unikey(seq):
      return seq[0].translate(trans)
  tree = ET.parse("tosort.xml")
  container = tree.find("entries")
  data = []
  for elem in container:
      keyd = elem.findtext("k")
      data.append((keyd, elem))
  print (data)
  data.sort(key=unikey)
  print (data)
  container[:] = [item[-1] for item in data]
  tree.write("sorted.xml", encoding="utf-8")
  </code></pre>
  
  <p>Here are <a href="http://effbot.org/zone/element-index.htm#installation" rel="nofollow noreferrer">instructions</a>
  to import elementtree module.
  When I import module this way :<code>import xml.etree.ElementTree as ET</code>, I get a message:</p>
  
  <pre><code>Traceback (most recent call last):
  File "pcs.py", line 19, in &lt;module&gt;
  container[:] = [item[-1] for item in data]
  File "/usr/lib/python3.1/xml/etree/ElementTree.py", line 210, in __setitem__
  assert iselement(element)
  AssertionError
  </code></pre>
  
  <p>When I use this method to import: <code>import elementtree.ElementTree as ET</code>, I get this message:</p>
  
  <pre><code>Traceback (most recent call last):
  File "pcs.py", line 4, in &lt;module&gt;
  import elementtree.ElementTree as ET
  File "/usr/local/lib/python3.1/dist-packages/elementtree/ElementTree.py", line 794, in &lt;module&gt;
  _escape = re.compile(eval(r'u"[&amp;&lt;&gt;\"\u0080-\uffff]+"'))
  File "&lt;string&gt;", line 1
  u"[&amp;&lt;&gt;\"\u0080-\uffff]+"
                         ^
  SyntaxError: invalid syntax
  </code></pre>
  
  <p>I use Python 3.1.3 (r313:86834, Nov 28 2010, 11:28:10). In python2.6 elementtree work without a problem.</p>
  
  <p>Content of tosort.xml:</p>
  
  <pre><code>&lt;xdxf&gt;
  &lt;entries&gt;
  &lt;ar&gt;&lt;k&gt;zaaaa&lt;/k&gt;definition1&lt;/ar&gt;
  &lt;ar&gt;&lt;k&gt;şaaaa&lt;/k&gt;definition2&lt;/ar&gt;
  ...
  ...
  &lt;/entries&gt;
  &lt;/xdxf&gt;
  </code></pre>