title: How can I convert XML into a Python object?
body: <p>I need to load an XML file and convert the contents into an object-oriented Python structure. I want to take this:</p>
  
  <pre><code>&lt;main&gt;
      &lt;object1 attr="name"&gt;content&lt;/object&gt;
  &lt;/main&gt;
  </code></pre>
  
  <p>And turn it into something like this:</p>
  
  <pre><code>main
  main.object1 = "content"
  main.object1.attr = "name"
  </code></pre>
  
  <p>The XML data will have a more complicated structure than that and I can't hard code the element names. The attribute names need to be collected when parsing and used as the object properties.</p>
  
  <p>How can I convert XML data into a Python object?</p>