title: Iterate all XML node generations in java DOM
body: <p>I want to check to see if an XML document contains a 'person' element anywhere inside. I can check all the first-generation elements very simply:</p>
  
  <pre><code>NodeList nodeList = root.getChildNodes();
  for(int i=0; i&lt;nodeList.getLength(); i++){
    Node childNode = nodeList.item(i);
    if (childNode.getNodeName() == "person") {
       //do something with it
    }
  }
  </code></pre>
  
  <p>And and I can add more loops to go into subelements, but I would have to know how many nested loops to put in to determine how far into the document to drill. I could nest 10 loops, and end up with a person element nested 12 elements deep in a given document. I need to be able to pull out the element not matter how deeply nested it is.</p>
  
  <p>Is there way to harvest elements from an entire document? Like return the text values of all  tags as an array or iterate over it?</p>
  
  <p>Something akin to python's elementtree 'findall' method perhaps:</p>
  
  <pre><code>for person in tree.findall('//person'):
     personlist.append(person)
  </code></pre>