title: Simple loop for all elements of an etree object?
body: <p>I've got a function to return a list from an etree element, but it doesn't look through nested elements.</p>
  
  <pre><code>&lt;elem&gt;
      &lt;variable id="getthis"&gt;
          &lt;!-- / --&gt;
      &lt;/variable&gt;
      &lt;if&gt;
          &lt;variable id="alsoGetThis"&gt;
              &lt;!-- Keep looping through all elements --&gt;
          &lt;/variable&gt;
      &lt;/if&gt;
  &lt;/elem&gt;
  </code></pre>
  
  <p>(I'm working with <a href="http://pastebin.com/vRRxfWiA" rel="nofollow">Valid XML</a>)</p>
  
  <p>So currently the variable within the <code>&lt;if&gt;</code> is ignored, so how can you loop through all levels of the tree? I'm assuming this is a simple task, but maybe I'm wrong. (I'm new to Python &amp; don't always think like a programmer)</p>
  
  <p>Python func to get the variables:</p>
  
  <pre><code>def collect_vars(self, elem):
      elemVars = []
      if elem.tag == 'variable':
          elemVars.append(elem.attrib['id'])
      elif e in elem == 'variable': # don't want to be doing these
          elemVars.append(e.attrib['id'])
      return elemVars
  </code></pre>
  
  <p>So all I want to end up with is the list <code>elemVars</code> containing all the variable IDs within the given <code>&lt;elem&gt;</code></p>