title: dom4j-java- how to get all elements (parent or children) within root that have specific element name
body: <p>I want to get the number of elements in an xml, which have specific name eg. name="while")</p>
  
  <p>The problem is that if I use the following code- I only get top level elements that have this name--</p>
  
  <pre><code>       for ( Iterator i = root.elementIterator( "while" ); i.hasNext(); ) {
              Element foo = (Element) i.next();
  </code></pre>
  
  <p>But any lower level "while" element is not part of the iterator...</p>
  
  <p>What is the most efficient way of obtaining all elements (whether top level or lower level) that have name="while"? Do I have to parse through all elements in document for this purpose?</p>