title: Java DOM: Get all parents list
body: <p>I Need to list all the Elements which contain at least one child. For example, in the below XML, H,I,T have at least one child field each. I Need to list out H,I,T only &amp; ignore other parents such as G_GT, Rec etc.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Doc&gt;
    &lt;Rec&gt;
      &lt;H&gt;
        &lt;Key&gt;H&lt;/Key&gt;
        &lt;F1&gt;1&lt;/F1&gt;
        &lt;I&gt;
          &lt;Key&gt;I&lt;/Key&gt;
          &lt;F2&gt;08&lt;/F2&gt;
          &lt;G_GT&gt;
            &lt;T&gt;
              &lt;Key&gt;T&lt;/Key&gt;
              &lt;F3&gt;1&lt;/F3&gt;
            &lt;/T&gt;
            &lt;T&gt;
              &lt;Key&gt;T&lt;/Key&gt;
              &lt;F3&gt;2&lt;/F3&gt;
            &lt;/T&gt;
          &lt;/G_GT&gt;
        &lt;/I&gt;
      &lt;/H&gt;
    &lt;/Rec&gt;
  &lt;/Doc&gt;
  </code></pre>
  
  <p>The Code should give Output as <strong>H,I,T</strong>.
  I am working on Java with DOM parser. Could anyone suggest how to do this in Java using DOM? I cannot use functions as getElementByTagName etc as I can get XML with different parent &amp; child names. Thus, I have to avoid any hardcoding of child or parent Name.</p>
  
  <p>Regards,
  Phil</p>