title: How to remove the special characters and & tokens(Invalid xml tokens) from xml file before giving to xml.sax parser in python
body: <p>Presently i am working on xml.sax parser to parse xml files</p>
  
  <p>suppose i had following code</p>
  
  <pre><code>filepath = 'users/file.xml'
  
  try:
      parser = xml.sax.make_parser( )
      parser.parse(open(filepath))
  
  except (xml.sax.SAXParseException), e:
          print "*** PARSER error: %s" % e
  </code></pre>
  
  <p><strong>file.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;tag1&gt;
    &lt;tag2&gt;
  &lt;P style="MARGIN: 0in 0in 0pt" class="MsoNormal"&gt;&lt;FONT size="3"&gt;&lt;SPAN style="FONT-FAMILY: Symbol; COLOR: black; mso-ascii-font-family: 'Times New Roman'"&gt;�&lt;/SPAN&gt;&lt;SPAN style="COLOR: black"&gt;&lt;FONT face="Times New Roman"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Position will manage 24 ED Rooms with 24/7 accountability&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
     &lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
     &lt;/tag2&gt;
  &lt;/tag1&gt;
  </code></pre>
  
  <p>When the parser reaches the &amp; in div tag it stopping execution and displaying the following error</p>
  
  <pre><code>*** PARSER error: users/file.xml:5:1: not well-formed &lt;invalid token&gt;
  </code></pre>
  
  <p>How to remove or escape all the invalid xml tokens before giving to parser from the xml file, is there any function to escape &amp; and special characters form the xml tags or else we need to loop through he xml file and remove each and every invalid token? but dont know how to do it. Can anyone please share the code of doing it.   </p>