title: XPath Parser java redundancy
body: <p>So I need to parse an XML file with XPath.
  All works well but if i have a tag which is present more than one time, my code displays all the subtags of all the same tags inside a tag.
  For example: i have a </p>
  
  <pre><code>&lt;a&gt;
    &lt;b&gt;&lt;/b&gt;
  &lt;/a&gt;
  &lt;c&gt;&lt;/c&gt;
  &lt;a&gt;
    &lt;b&gt;&lt;/b&gt;
  &lt;/a&gt;
  </code></pre>
  
  <p>the output will be :</p>
  
  <pre><code>a
   b
   b
  c
  a
   b
   b
  </code></pre>
  
  <p>my code is this :</p>
  
  <pre><code> public void parseFileXPath() throws ParserConfigurationException, IOException, SAXException, XPathExpressionException {
      DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
      Document doc = documentBuilder.parse(file);
      doc.getDocumentElement().normalize();
  
      XPathFactory factory = XPathFactory.newInstance();
      XPath xpath = factory.newXPath();
  
      String expression;
      Node node;
      NodeList nodeList;
  
      expression="/*";
      node = (Node) xpath.evaluate(expression,doc, XPathConstants.NODE);
      //System.out.println(node.getNodeName());
  
      expression="/frogans-fsdl/*";
      nodeList = (NodeList) xpath.evaluate(expression,doc, XPathConstants.NODESET);
  
  
      NodeList nodeList1;
  
  
      for (int i = 0; i &lt; nodeList.getLength(); i++) {
          String aTag = nodeList.item(i).getNodeName();
  
          System.out.println(aTag);
          expression="/frogans-fsdl/"+aTag+"/*";
          nodeList1 = (NodeList) xpath.evaluate(expression,doc,XPathConstants.NODESET);
  
          for (int j = 0; j &lt; nodeList1.getLength(); j++) {
  
              System.out.println("\t"+nodeList1.item(j).getNodeName());
              //TODO
              //Display what's inside each tag
          }
  
          expression="";
      }
  
  
  
  }
  </code></pre>
  
  <p>Any help please ?</p>