title: How to convert an XML string to a dictionary?
body: <p>I have a program that reads an XML document from a socket. I have the XML document stored in a string which I would like to convert directly to a Python dictionary, the same way it is done in Django's <code>simplejson</code> library.</p>
  <p>Take as an example:</p>
  <pre><code>str =&quot;&lt;?xml version=&quot;1.0&quot; ?&gt;&lt;person&gt;&lt;name&gt;john&lt;/name&gt;&lt;age&gt;20&lt;/age&gt;&lt;/person&quot;
  dic_xml = convert_to_dic(str)
  </code></pre>
  <p>Then <code>dic_xml</code> would look like <code>{'person' : { 'name' : 'john', 'age' : 20 } }</code></p>