title: Parse Nested XML tags with the same name
body: <p>Let's take a simple XML document:</p>
  
  <pre><code>  &lt;x&gt;
      &lt;e&gt;
          &lt;e&gt;
              &lt;e&gt;Whatever 1&lt;/e&gt;
          &lt;/e&gt;
      &lt;/e&gt;
      &lt;e&gt;
          &lt;e&gt;
              &lt;e&gt;Whatever 2&lt;/e&gt;
          &lt;/e&gt;
      &lt;/e&gt;
      &lt;e&gt;
          &lt;e&gt;
              &lt;e&gt;Whatever 3&lt;/e&gt;
          &lt;/e&gt;
      &lt;/e&gt;
    &lt;/x&gt; 
  </code></pre>
  
  <p>Using the standard org.w3c.dom, I can get the nodes in X by doing..</p>
  
  <pre><code>NodeList fullnodelist = doc.getElementsByTagName("x");
  </code></pre>
  
  <p>But if I want to return the next set of "e" I try to use something like ..</p>
  
  <pre><code>Element element = (Element) fullnodelist.item(0);
  NodeList nodes = pelement.getElementsByTagName("e");
  </code></pre>
  
  <p>Expecting it to return "3" nodes (because there are 3 sets of "e"), but instead, it returns "9" - becuase it gets all entries with "e" apperently.</p>
  
  <p>This would be fine in the above case, because I could probably iterate through and find what I'm looking for. The problem I'm having is that when the XML file looks like the following:</p>
  
  <pre><code>  &lt;x&gt;
      &lt;e&gt;
        &lt;pattern&gt;whatever&lt;/pattern&gt;
        &lt;blanks&gt;
          &lt;e&gt;Something Else&lt;/e&gt;
        &lt;/blanks&gt;
      &lt;/e&gt;
      &lt;e&gt;
        &lt;pattern&gt;whatever&lt;/pattern&gt;
        &lt;blanks&gt;
          &lt;e&gt;Something Else&lt;/e&gt;
        &lt;/blanks&gt;
      &lt;/e&gt;
    &lt;/x&gt;
  </code></pre>
  
  <p>When I request the "e" value, it returns 4, instead of (what i expect) 2.</p>
  
  <p>Am I just not understanding how the DOM parsing works? Typically in the past I have used my own XML documents so I would never name the items like this, but unfortunately this is not my XML file and I have no choice to work like this.</p>
  
  <p>What I thought I would do is write a loop that "drills down" nodes so that I could group each node together...</p>
  
  <pre><code>public static NodeList getNodeList(Element pelement, String find)
      {
          String[] nodesfind = Utilities.Split(find, "/");
          NodeList nodeList = null;
  
          for (int i = 0 ; i &lt;= nodesfind.length - 1; i++ )
          {
              nodeList = pelement.getElementsByTagName( nodesfind[i] );
              pelement = (Element)nodeList.item(i);
          }
  
          // value of the nod we are looking for
          return nodeList;
      }
  </code></pre>
  
  <p>.. So that if you passed "s/e" into the function, it would return the 2 nodes that I'm looking for (or elements, maybe I'm using the terminology incorrect?). instead it returns all of the "e" nodes within that node.</p>
  
  <p>I'm using J2SE for this, so options are rather limited. I can't use any third party XML Parsers.</p>
  
  <p>Anyway, if anyone is still with me and has a suggestion, it would be appreciated.</p>