title: Efficient way to iterate through xml elements
body: <p>I have a xml like this:</p>
  
  <pre><code>&lt;a&gt;
      &lt;b&gt;hello&lt;/b&gt;
      &lt;b&gt;world&lt;/b&gt;
  &lt;/a&gt;
  &lt;x&gt;
      &lt;y&gt;&lt;/y&gt;
  &lt;/x&gt;
  &lt;a&gt;
      &lt;b&gt;first&lt;/b&gt;
      &lt;b&gt;second&lt;/b&gt;
      &lt;b&gt;third&lt;/b&gt;
  &lt;/a&gt;
  </code></pre>
  
  <p>I need to iterate through all <code>&lt;a&gt;</code> and <code>&lt;b&gt;</code> tags, but I don't know how many of them are in document. So I use <code>xpath</code> to handle that:</p>
  
  <pre><code>from lxml import etree
  
  doc = etree.fromstring(xml)
  
  atags = doc.xpath('//a')
  for a in atags:
      btags = a.xpath('b')
      for b in btags:
              print b
  </code></pre>
  
  <p>It works, but I have pretty big files, and <code>cProfile</code> shows me that <code>xpath</code> is very expensive to use.</p>
  
  <p>I wonder, maybe there is there more efficient way to iterate through indefinitely number of xml-elements?</p>