title: how to parse xml to hashmap?
body: <p>I have an example of an xml I want to parse</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;Details&gt;
      &lt;detail-a&gt;
  
          &lt;detail&gt; attribute 1 of detail a &lt;/detail&gt;
          &lt;detail&gt; attribute 2 of detail a &lt;/detail&gt;
          &lt;detail&gt; attribute 3 of detail a &lt;/detail&gt;
  
      &lt;/detail-a&gt;
  
      &lt;detail-b&gt;
          &lt;detail&gt; attribute 1 of detail b &lt;/detail&gt;
          &lt;detail&gt; attribute 2 of detail b &lt;/detail&gt;
  
      &lt;/detail-b&gt;
  
  
  &lt;/Details&gt;
  </code></pre>
  
  <p>I would like from this xml to write a method that will parse it to hashmap that the key is a string and the value is a list of strings.</p>
  
  <p>for instance : key "detail a" value={"attribute 1 of detail a","attribute 2 of detail a","attribute 3 of detail a"}</p>
  
  <p>and so on..</p>
  
  <p>what is the best way to do this ? because I got confused :\</p>
  
  <p>I got this far to try to print detail-a and detail-b but I get blank...</p>
  
  <pre><code>public static void main(String[] args) {
      // TODO Auto-generated method stub
  
      DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
  
          DocumentBuilder builder;
          try {
              builder = factory.newDocumentBuilder();
              File f= new File("src/Details.xml");
              Document doc=builder.parse(f);
              Element root=doc.getDocumentElement();
              NodeList children=root.getChildNodes();
              for(int i=0;i&lt;children.getLength();i++)
              {
                  Node child=children.item(i);
                  if (child instanceof Element)
                  {
                      Element childElement=(Element) child;
                      Text textNode=(Text)childElement.getFirstChild();
                      String text=textNode.getData().trim();
                      System.out.println(text);
  
                  }
              }
  
          } catch (ParserConfigurationException e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();   
          } catch (SAXException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  </code></pre>