title: Python parsing XML using ElementTree based on IF Conditions
body: <p>Using Python, I'm trying to parse an XML file to retrieve the value of an element based on the value of the 'name' attribute AND the value of a child element based on the value of the 'name' attribute as well.</p>
  
  <p>The conditions are:</p>
  
  <p>If Category attribute is 3 in 'test' element, then grab the value of the 'name' attribute</p>
  
  <p>AND</p>
  
  <p>Grab the value of the 'color' element IF the value of the 'name' attribute is 'enable'</p>
  
  <p>Example Code:</p>
  
  <pre><code>&lt;test category="1"&gt;
   &lt;test category="2"&gt;
    &lt;test name="1" category="3"&gt;
     &lt;color name="disable"&gt;blue&lt;/color&gt;
     &lt;color name="disable"&gt;yellow&lt;/color&gt;
     &lt;color name="enable"&gt;red&lt;/color&gt;
     &lt;color name="disable"&gt;orange&lt;/color&gt;
    &lt;/test&gt;
    &lt;test name="2" category="3"&gt;
     &lt;color name="disable"&gt;green&lt;/color&gt;
     &lt;color name="disable"&gt;purple&lt;/color&gt;
     &lt;color name="enable"&gt;white&lt;/color&gt;
     &lt;color name="disable"&gt;gray&lt;/color&gt;
    &lt;/test&gt;
   &lt;/test&gt;
  &lt;/test&gt;
  </code></pre>
  
  <p>Expected Results:</p>
  
  <p>1 red</p>
  
  <p>2 white</p>
  
  <p>My Current Code:</p>
  
  <pre><code>import xml.etree.ElementTree as ET
  tree = ET.parse('C:/colors.xml')
  root = tree.getroot()
  
  for test in root.getiterator('test'):
  
  if test.attrib['category']=="3":
      print test.attrib['name']
  </code></pre>
  
  <p>This gives me: </p>
  
  <pre><code>1
  2
  </code></pre>
  
  <p>I've tried a nested FOR to get the value of the color element, but everything I tried seems to start from the beginning.</p>
  
  <p>Any assistance would be appreaciated!</p>
  
  <p>Thanks </p>