title: Reading data from xml file and storing as key value pair
body: <p>I have following data in XML file where i have stored some testdata.</p>
  
  <pre><code>&lt;root&gt;
      &lt;event&gt;
          &lt;auth&gt;
              &lt;admin&gt;
                  &lt;username&gt;testust@mail.com&lt;/username&gt;
                  &lt;password&gt;pass^&amp;*%s&lt;/password&gt;
                  &lt;name&gt;temp&lt;/name&gt;
              &lt;/admin&gt;
  
              &lt;normal-user&gt;
                  &lt;username&gt;test_usera1@mail.com&lt;/username&gt;
                  &lt;password&gt;test45#&lt;/password&gt;
              &lt;/normal-user&gt;
  
          &lt;/auth&gt;
      &lt;/event&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>I'm trying to read the data from xml in key value pair.
  e.g.  <code>event.auth.admin.username = testust@mail.com</code> . Its working fine if i put all other data node under admin but if i user another node <code>&lt;normal-user&gt;</code> then it append this node name in older one.</p>
  
  <p>Actual : <code>event.auth.admin.normal-user.username = test_usera1@mail.com</code></p>
  
  <p>Expected : <code>event.auth.normal-user.username = testust@mail.com</code></p>
  
  <p>I'm using below code for that:</p>
  
  <pre><code>private StringBuilder keyName = new StringBuilder();
  Logger printLog = Logger.getLogger("API Testing Logger");
  
  public void loadXml() {
      File folder = new File("resources");
      File[] listOfFiles = folder.listFiles();
  
      for (File file : listOfFiles) {
          if (file.isFile() &amp;&amp; file.getName().endsWith(".xml")) {
  
              printLog.log(Level.INFO, "xml file loaded : " + file.getName());
  
              try {
                  File inputFile = new File(folder.getAbsolutePath() + "/" + file.getName());
                  DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
                  DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
                  Document doc = dBuilder.parse(inputFile);
                  doc.getDocumentElement().normalize();
                  new XmlLoader().fillDataInProperty(doc.getDocumentElement());
  
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public void fillDataInProperty(Node node) {
  
      if (!node.getNodeName().equals("root")) {
  
          if (node.getChildNodes().getLength() == 1) {
              keyName.append(node.getNodeName());
              int i = keyName.indexOf(node.getNodeName());
              if (i != -1) {
                  keyName.delete(i, i + keyName.length());
              }
  
          } else {
              keyName.append( node.getNodeName().concat("."));
  
          }
      }
  
      NodeList nodeList = node.getChildNodes();
      for (int i = 0; i &lt; nodeList.getLength(); i++) {
  
          Node currentNode = nodeList.item(i);
          if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
              fillDataInProperty(currentNode);
          }
      }
  }
  </code></pre>