title: JAVA element.getElementsByTagName Restrict to Top Level
body: <p>I have an XML file as follows:</p>
  
  <pre><code>&lt;rootNode&gt;
      &lt;link&gt;http://rootlink/&lt;/link&gt;
      &lt;image&gt;
          &lt;link&gt;http://imagelink/&lt;/link&gt;
          &lt;title&gt;This is the title&lt;/title&gt;
      &lt;/image&gt;
  &lt;/rootNode&gt;
  </code></pre>
  
  <p>The XML Java code using DOM is as follows:</p>
  
  <pre><code>NodeList rootNodeList = element.getElementsByTagName("link");
  </code></pre>
  
  <p>This will give me all of the "link" elements including the top level and the one inside the "image" node.</p>
  
  <p>Is there a way to just get the "link" tags for rootNode within one level and not two such as is the case for the image link?  That is, I just want the <a href="http://rootlink/" rel="noreferrer">http://rootlink/</a> "link".</p>