title: Store xml value as a Map using XPATH using JAVA
body: <p>I am using XPATH to parse xml document,please find the xml below</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
      &lt;soap:Body&gt;
          &lt;bookEvent&gt;
              &lt;bookName&gt;harry_potter&lt;/bookName&gt;
              &lt;bookEntity&gt;comic&lt;/bookEntity&gt;
              &lt;bookEntityId&gt;10987645&lt;/bookEntityId&gt;
              &lt;bookParameter&gt;
                  &lt;name&gt;Name1&lt;/name&gt;
                  &lt;value&gt;value1&lt;/value&gt;
              &lt;/bookParameter&gt;
              &lt;bookParameter&gt;
                  &lt;name&gt;Name2&lt;/name&gt;
                  &lt;value&gt;value2&lt;/value&gt;
              &lt;/bookParameter&gt;
              &lt;bookParameter&gt;
                  &lt;name&gt;Name3&lt;/name&gt;
                  &lt;value&gt;value3&lt;/value&gt;
              &lt;/bookParameter&gt;
              &lt;bookParameter&gt;
                  &lt;name&gt;Name4&lt;/name&gt;
                  &lt;value&gt;value4&lt;/value&gt;
              &lt;/bookParameter&gt;
              &lt;bookParameter&gt;
                  &lt;name&gt;Name5&lt;/name&gt;
                  &lt;value&gt;value5&lt;/value&gt;
              &lt;/bookParameter&gt;
          &lt;/bookEvent&gt;
      &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  
  <p>Here I would like to convert BookParameters to Map like below</p>
  
  <pre><code>{"Name1":"value1","Name2":"value2" etc}
  </code></pre>
  
  <p>I have tried the below code and i can get a Map but not in the expected format,</p>
  
  <pre><code>      try{
          Map&lt;String,String&gt; eventParameters = new HashMap&lt;&gt;();
          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
          DocumentBuilder builder = factory.newDocumentBuilder();
          Document doc = builder.parse("book.xml");
          XPathFactory xPathfactory = XPathFactory.newInstance();
          XPath xpath = xPathfactory.newXPath();
          NodeList nodeList = (NodeList)xpath.compile("//bookEvent//eventParameter").evaluate(doc, XPathConstants.NODESET);
          for (int i = 0; i &lt; nodeList.getLength(); i++) {
              Node node = nodeList.item(i);
              if(node.hasChildNodes()) {
                  NodeList childNodes = node.getChildNodes();
                  for (int j = 0; j &lt; childNodes.getLength(); j++) {
                      Node childNode = childNodes.item(j);
                      if (childNode.getNodeType() == Node.ELEMENT_NODE) {
                          System.out.println(childNode.getNodeName()+"::"+childNode.getNodeValue()+"::"+childNode.getTextContent());
                          eventParameters.put(childNode.getTextContent(),childNode.getTextContent());
                      }
                  }
              }
          }
          System.out.println("print map::"+eventParameters);
      } catch (Exception e) {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>The output looks like this</p>
  
  <pre><code>print map::{Name3=Name3, Name4=Name4, value5=value5, Name5=Name5, value2=value2, value1=value1, value4=value4, value3=value3, Name1=Name1, Name2=Name2}
  </code></pre>
  
  <p>Please somebody guide me to create a below map from the xml,Any help would be appreciable.</p>
  
  <pre><code>{"Name1":"value1","Name2":"value2" etc}
  </code></pre>