title: How to parse xml string into dict or json in Python?
body: <p>I have a list of strings which is in xml format, but not from an xml file, so I can't use an xml parser to read in the file and parse the elements, as below:</p>
  <pre><code>&lt;Pattern id=&quot;001&quot; name=&quot;Tesla&quot; type=&quot;car&quot;&gt;
      &lt;trigger&gt;electric&lt;/trigger&gt;
      &lt;confidence&gt;0.9&lt;/confidence_booster&gt;
      &lt;condition&gt;
        {car ^12}
      &lt;/condition&gt;
  &lt;/Pattern&gt;
  </code></pre>
  <p>Is there any convenient way to parse this str as a dictionary:</p>
  <pre><code>pattern = {&quot;id&quot;:&quot;001&quot;, 
            &quot;name&quot;:&quot;Tesla&quot;,
            &quot;type&quot;:&quot;car&quot;, 
            &quot;trigger&quot;: &quot;electric&quot;, 
            &quot;confidence&quot;:0.9, 
            &quot;condition&quot;: &quot;{car ^12}&quot;
            }
  </code></pre>
  <p>It's also fine if it can be parsed into a json object.</p>