title: convert xml to java hashmap jsoup
body: <p>I am trying to convert any given xml to hash map. I know this can somehow be done using JAXB. I was trying using jsoup. My code is below</p>
  
  <pre><code> public static Map&lt;String,Object&gt; xmlToMapAll(String xml){
              List&lt;Map&lt;String,Object&gt;&gt; list = new ArrayList&lt;Map&lt;String,Object&gt;&gt;();
              Map&lt;String,Object&gt; map = new HashMap&lt;String,Object&gt;();
              try{
                  Document xmlDoc = Jsoup.parse(xml, "", Parser.xmlParser());
                  Elements eles =xmlDoc.getAllElements();
                  for(Element ele: eles){
                      Map&lt;String,Object&gt; mi = new HashMap&lt;String,Object&gt;();
                      if(ele.children().size()&gt;1){
                          mi = getChilds(ele.children());
                      }else{
                          mi.put(ele.tagName(), ele.ownText());
                      }
                      list.add(mi);
                      //map.putAll(mi);
                  }
  
                  map.put("data", list);
                  map.put("Status", "SUCCESS");
              }catch(Exception ce){
                  log.error("IndoXMLParseUtil.xmlToMapAll() ce "+IndoUtil.getFullLog(ce));
              }
              return map;
          }
          public static Map&lt;String,Object&gt; getChilds(Elements childs){
              Map&lt;String,Object&gt; map = new HashMap&lt;String,Object&gt;();
              for(Element child: childs){
                  if(child.children().size()&gt;0){
                      map = getChilds(child.children());
                  }else{
                      map.put(child.tagName(), child.ownText());
                  }
              }
              return map;
          }
  
      public static void main(String args[]){
              String xml="&lt;ExtMessage xmlns=\"com/test/schema/evExtQMainPkgQuotaResp\"&gt;   
  &lt;ExtQMainPkgQuotaResp&gt;     
  &lt;ServiceNumber&gt;1234567&lt;/ServiceNumber&gt;
  &lt;Source&gt;&lt;a&gt;10&lt;/a&gt;&lt;b&gt;11&lt;/b&gt;&lt;a&gt;12&lt;/a&gt;&lt;/Source&gt;
  &lt;Status&gt;Success&lt;/Status&gt;
      &lt;ErrorMessage/&gt;&lt;InitialQuota&gt;2621440&lt;/InitialQuota&gt; 
          &lt;UsedQuota&gt;62859.49&lt;/UsedQuota&gt;   
      &lt;/ExtQMainPkgQuotaResp&gt; &lt;/ExtMessage&gt; ";
                  Map&lt;String, Object&gt;  ds =  xmlToMapAll(xml);
                  System.out.println("IndoXMLParseUtil.main() "+ds);
              }
  </code></pre>
  
  <p><strong>output:</strong></p>
  
  <blockquote>
    <p>{Status=SUCCESS, data=[{#root=}, {extmessage=}, {errormessage=, b=11,
    status=Success, a=12, initialquota=2621440, usedquota=62859.49},
    {servicenumber=6285770355730}, {b=11, a=12}, {a=10}, {b=11}, {a=12},
    {status=Success}, {errormessage=}, {initialquota=2621440},
    {usedquota=62859.49}]}</p>
  </blockquote>
  
  <p>Problem is I am getting repeated data. Also I believe there are always better ideas out here.</p>