title: Java. Moving in a xml with the same tag name as child
body: <p>The problem I have is that I have to work with an xml file the providers of the company I work for sent to me.<br/>
  This would not be a problem if the xml was well constructed but it is not at all.<br/></p>
  
  <pre><code>&lt;catalog&gt;
      &lt;product&gt;
          &lt;ref&gt;4780&lt;/ref&gt;
               .
               .
               .
          &lt;arrivals&gt;
              &lt;product&gt;
                  &lt;image title="AMARILLO"&gt;AMA&lt;/image&gt;
                  &lt;size&gt;S/T &lt;/size&gt;
              &lt;/product&gt;
              &lt;product&gt;
                  &lt;image title="AZUL"&gt;AZUL&lt;/image&gt;
                  &lt;size&gt;S/T &lt;/size&gt;
              &lt;/product&gt;
          &lt;/arrivals&gt;
      &lt;/product&gt;
  &lt;/catalog&gt;
  </code></pre>
  
  <p>As you can see, the tag <code>&lt;product&gt;</code> have all the information of the product but there are more tags named <code>&lt;product&gt;</code> to distinguish when there are different colors.<br/>
  This is the code I use to move in the xml.</p>
  
  <pre><code>doc = db.parse("filename.xml");
  Element esproducte = (Element)doc.getElementsByTagName("product").item(0);
  
  NodeList nArrv = esproducte.getElementsByTagName("arrivals");
  Element eArrv = (Element) nArrv.item(0);
  NodeList eProds = eArrv.getElementsByTagName("product");//THIS THING
  
  for(int l=0; l&lt;eProds.getLength(); l++)
  {
  Node ln = eProds.item(l);
  if (ln.getNodeType() == Node.ELEMENT_NODE)
  {
      Element le = (Element) ln;
  
      //COLORS / IMAGES / CONFIGS
      NodeList nimgcol = le.getElementsByTagName("image");
      Element eimgcol = (Element) nimgcol.item(0);
      System.out.println("Name of the color " + eimgcol.getTextContent());
  }
  </code></pre>
  
  <p>What happens is that the print is reapeated more times it should and I think it's because of the parent <code>&lt;product&gt;</code>. I thought it shouldn't happen because where I wrote <code>//THIS THING</code> I take into account the fact that <code>&lt;product&gt;</code> is set in <code>&lt;arrivals&gt;</code>. But it is not working.<br/>
  What should I modify in the code to move only 2 times in the for and not 3, which is what happen in this case?</p>
  
  <p><b>Solution:</b></p>
  
  <pre><code>NodeList eProds = eArrv.getElementsByTagName("product");//THIS THING
  </code></pre>
  
  <p>to</p>
  
  <pre><code>NodeList eProds = eArrv.getChildNodes();//THIS THING
  </code></pre>
  
  <p>And the rest exactly the same. Works perfect.</p>