title: Use BeautifulSoup to Iterate over XML to pull specific tags and store in variable
body: <p>I'm fairly new to programming and have been trying to find a solution for this but all I can find are bits and pieces with no real luck putting it all together.</p>
  
  <p>I'm trying to use <code>BeautifulSoup4</code> in <code>python</code> to scrape some <code>xml</code> and store the text value in between specific tags in variables. The data is from a med student training program and right now everything needed has to be found manually. So I'm trying to increase efficiency a bit with a scraping program.</p>
  
  <p>Let's say for example that I was looking at this type of test data to experiment with:</p>
  
  <pre><code>&lt;AllergyList&gt;
  &lt;Allergy&gt;
      &lt;Deleted&gt;n&lt;/Deleted&gt;
      &lt;Status&gt;
          &lt;Active/&gt;
      &lt;/Status&gt;
      &lt;ExternalID/&gt;
      &lt;Patient&gt;
          &lt;ExternalID/&gt;
          &lt;FirstName&gt;Testcase&lt;/FirstName&gt;
          &lt;LastName&gt;casetest&lt;/LastName&gt;
      &lt;/Patient&gt;
      &lt;Allergen&gt;
          &lt;Name&gt;Flagyl (metronidazole)&lt;/Name&gt;
          &lt;Drug&gt;
             &lt;NDCID&gt;00025182151,00025182131,00025182150&lt;/NDCID&gt;
          &lt;/Drug&gt;
      &lt;/Allergen&gt;
      &lt;Reaction&gt;difficulty breathing&lt;/Reaction&gt;
      &lt;OnsetDate&gt;02/02/2013&lt;/OnsetDate&gt;
   &lt;/Allergy&gt;
  &lt;Allergy&gt;
      &lt;Deleted&gt;n&lt;/Deleted&gt;
      &lt;Status&gt;
          &lt;Active/&gt;
      &lt;/Status&gt;
      &lt;ExternalID/&gt;
      &lt;Patient&gt;
          &lt;ExternalID/&gt;
          &lt;FirstName&gt;Testcase&lt;/FirstName&gt;
          &lt;LastName&gt;casetest&lt;/LastName&gt;
      &lt;/Patient&gt;
      &lt;Allergen&gt;
          &lt;Name&gt;Bactrim (sulfamethoxazole-trimethoprim)&lt;/Name&gt;
          &lt;Drug&gt;
              &lt;NDCID&gt;13310014501,49999023220&lt;/NDCID&gt;
          &lt;/Drug&gt;
      &lt;/Allergen&gt;
      &lt;Reaction&gt;swelling&lt;/Reaction&gt;
      &lt;OnsetDate&gt;05/03/2002&lt;/OnsetDate&gt;
    &lt;/Allergy&gt;
    &lt;Number&gt;2&lt;/Number&gt;
  &lt;/AllergyList&gt;
  </code></pre>
  
  <p>I've been trying to pull the <code>&lt;Name&gt;</code> tag from in between multiple <code>&lt;Allergen&gt;</code> tags as well as the respective data from in between the <code>&lt;Onsetdate&gt;</code> and <code>&lt;Reaction&gt;</code> tags while storing the results of the pull into respective variables. </p>
  
  <p>So for example I would want to pull <code>Flagyl (metronidazole)</code>, <code>difficulty breathing</code>, <code>02/02/2013</code>, then <code>Bactrim (sulfamethoxazole-trimethoprim)</code>, <code>swelling</code>, <code>05/03/2002</code>, and so on while placing them in separate variables that I can use later.</p>
  
  <p>Pulling the first set from the <code>&lt;Allergen&gt;</code> tag is easy but I'm having trouble figuring out how to iterate over the <code>xml</code> and storing the pulled data into variables. I've been trying to use a for loop while storing the data into an array or list but the way I've been writing it I always pull the same data over and over again depending on the number of iterations I calculate from the <code>len()</code> function and have since failed to store any of it into an array.  </p>
  
  <p>I've been racking my brain about this for a while now and I think I may just not be that smart so any help or even pointing me in the right direction would be immensely appreciated.</p>