title: Escape unescaped characters in XML with Python
body: <p>I need to escape special characters in an invalid XML file which is about 5000 lines long. Here's an example of the XML that I have to deal with:</p>
  
  <pre><code>&lt;root&gt;
   &lt;element&gt;
    &lt;name&gt;name &amp; surname&lt;/name&gt;
    &lt;mail&gt;name@name.org&lt;/mail&gt;
   &lt;/element&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>Here the problem is the character "&amp;" in the name. How would you escape special characters like this with a Python library? I didn't find a way to do it with <a href="http://www.crummy.com/software/BeautifulSoup" rel="nofollow noreferrer">BeautifulSoup</a>.</p>