title: Parse XML to dictionary in Python
body: <p>I have the following xml file. I need to automate find/replace some strings in a bunch of files for different environment. I am using python 2.7. I need to pass the environment name and read the xml into a dictionary or array, which I can then use to find/replace the strings. I have tried using ElementTree, but unsure how to build dict containing old/new texts for each environment. Any suggestions please..</p>
  
  <pre><code>     &lt;?xml version="1.0" encoding="utf-8" ?&gt;
      &lt;Config&gt;
      &lt;Environment env="Support"&gt;
        &lt;sitedir path="d:\Support_463\REST Elements\Sites"/&gt;
        &lt;workflowdir path="d:\Support_463\REST 
      Elements\Sites\Resources\Workflows"/&gt;
        &lt;sitereplacements&gt;
          &lt;text old="zz-dev" new="zz-supp"/&gt;
          &lt;text old="yhz" new="vr"/&gt;
          &lt;text old="ax7" new="sh66^"/&gt;
        &lt;/sitereplacements&gt;
        &lt;workflowreplacements&gt;
          &lt;text old="zz-dev" new="zz-suppx"/&gt;
          &lt;text old="yhsxz" new="v*&amp;9r"/&gt;
          &lt;text old="ax7" new="(()&amp;4fg"/&gt;
        &lt;/workflowreplacements&gt;
  &lt;/Environment&gt;
  &lt;Environment env="Test"&gt;
        &lt;sitedir path="d:\Test_463\REST Elements\Sites"/&gt;
        &lt;workflowdir path="d:\Test_463\REST Elements\Sites\Resources\Workflows"/&gt;
        &lt;sitereplacements&gt;
          &lt;text old="zz-dev" new="zz-test"/&gt;
          &lt;text old="yhz" new="vxxAr"/&gt;
          &lt;text old="ax7" new="s8%6^"/&gt;
        &lt;/sitereplacements&gt;
        &lt;workflowreplacements&gt;
          &lt;text old="zz-dev" new="zz-testx"/&gt;
          &lt;text old="yhsxz" new="vr"/&gt;
          &lt;text old="ax7" new="$%^"/&gt;
        &lt;/workflowreplacements&gt;
  &lt;/Environment&gt;
  &lt;!--&lt;Environment env="Preprod"&gt;
        &lt;sitedir path=""/&gt;
        &lt;workflowdir path=""/&gt;
        &lt;sitereplacements&gt;
          &lt;text old="" new=""/&gt;
          &lt;text old="" new=""/&gt;
          &lt;text old="" new=""/&gt;
        &lt;/sitereplacements&gt;
        &lt;workflowreplacements&gt;
          &lt;text old="" new=""/&gt;       
          &lt;text old="" new=""/&gt;
          &lt;text old="" new=""/&gt;
        &lt;/workflowreplacements&gt;--&gt;
  &lt;/Environment&gt;
  </code></pre>
  
  <p></p>