title: Read xml file with more than one value in one tag in Java
body: <p>I have xml file like this </p>
  
  <pre><code>  &lt;Sample_Data&gt;
      &lt;lastname Name="lastname" Value="FIRSTNAME" /&gt;
      &lt;firstname Name="firstname" Value="LASTNAME" /&gt;
      &lt;DM Name="DM" Value="93.2" /&gt;
      &lt;CP Name="CP" Value="7.7" /&gt;
    &lt;/Sample_Data&gt;
  </code></pre>
  
  <p>I need to read this file with java and I use code like this:</p>
  
  <pre><code> try {
  
      DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
      Document doc = dBuilder.parse("File.xml");
  
      doc.getDocumentElement().normalize();
  
      System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
  
      NodeList nList = doc.getElementsByTagName("Sample_Data");
  
      System.out.println("----------------------------");
  
      for (int temp = 0; temp &lt; nList.getLength(); temp++) {
  
          Node nNode = nList.item(temp);
  
          System.out.println("\nCurrent Element :" + nNode.getNodeName());
  
          if (nNode.getNodeType() == Node.ELEMENT_NODE) {
  
              Element eElement = (Element) nNode;
  
  
              System.out.println("First Name : " + eElement.getElementsByTagName("firstname").item(0).getTextContent());
              System.out.println("Last Name : " + eElement.getElementsByTagName("lastname").item(0).getTextContent());
              System.out.println("DM : " + eElement.getElementsByTagName("DM").item(0).getTextContent());
              System.out.println("CP : " + eElement.getElementsByTagName("CP").item(0).getTextContent());
  
          }
      }
  
      } catch (Exception e) {
      e.printStackTrace();
      }
  </code></pre>
  
  <p>But I can't get values of firstname, lastname, DM and CP I get empty values for them.</p>
  
  <p>Can someone help me to resolve this problem?</p>