title: How to best iterate (breadth-first) over an lxml etree using Python
body: <p>I'm trying to wrap my head around lxml (new to this) and how I can use it to do what I want to do.  I've got an well-formed and valid XML file</p>
  
  <pre><code>&lt;root&gt;
    &lt;a&gt;
      &lt;b&gt;Text&lt;/b&gt;
      &lt;c&gt;More text&lt;/c&gt;
    &lt;/a&gt;
    &lt;!-- some comment --&gt;
    &lt;a&gt;
      &lt;d id="10" /&gt;
    &lt;/a&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>something like this.  Now I'd like to visit the children breadth-first, and the best I can come up with is something like this:</p>
  
  <pre><code>for e in xml.getroot()[0].itersiblings() :
      print(e.tag, e.attrib)
  </code></pre>
  
  <p>and then take it from there.  However, this gives me <em>all</em> elements including comments</p>
  
  <pre><code>a {}
  &lt;built-in function Comment&gt; {}
  a {}
  </code></pre>
  
  <p>How do I skip over comments?  Is there a better way to iterate over the direct children of a node?</p>
  
  <p>In general, what are the recommendations to parse an XML tree vs. event-driven pull-parsing using, say, <code>iterparse()</code>?</p>