getElementsByTagName returns 2 times more elements than actually exists

311 Views Asked by At

I have parsing XML documents with Java 1.7. When I run the function document.getElementByTagName("Product"), I get a number of 6000, but if I open it with Notepad++, I see only 3000 entries.

I have problem with looping through all elements with the wrong number of entries.

1

There are 1 best solutions below

0
On BEST ANSWER

I solved the problem. The problem was with the XML file. The parent Node had the same name as one of the Children nodes. for example.

> <products>
>          <product>
>                  <name>Blbalbal</name>
>                  <size>14</size>
>                  <cost>2000 $</cost>
>                  <link>
>                        <product>www.somthing.com</product>
>                  </link>
>          </product>
>          <product>
>                  <name>Product2</name>
>                  <size>123</size>
>                  <cost>2 $</cost>
>                  <link>
>                        <product>www.somthing2.com</product>
>                  </link>
>          </product>
> </products>

Thats why it, each entry counted twice