title: how to read xml in java?
body: <p>i have following xml :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
  &lt;root&gt; 
  &lt;processid&gt;processid_1111&lt;/processid&gt;
  &lt;suggestion&gt;
         &lt;geo1&gt;a&lt;/geo1&gt;
         &lt;geo2&gt;b&lt;/geo2&gt;
         &lt;geo3&gt;c&lt;/geo3&gt;
         &lt;standarddatasuggestion&gt;account1&lt;/standarddatasuggestion&gt;
  &lt;/suggestion&gt;
  &lt;suggestion&gt;
        &lt;geo1&gt;d&lt;/geo1&gt;
        &lt;geo2&gt;e&lt;/geo2&gt;
        &lt;geo3&gt;f&lt;/geo3&gt;
        &lt;geo4&gt;g&lt;/geo4&gt;
        &lt;standarddatasuggestion&gt;account2&lt;/standarddatasuggestion&gt;
  &lt;/suggestion&gt;
  &lt;taskid&gt;taskid_111&lt;/taskid&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>i want to design a method that can take node name and on the basis of node name it return corresponding node and it's value in map objects.please help me to sort out above problem.</p>
  
  <p>i tried it:</p>
  
  <pre><code>public SortedMap[] getObjectValueFromXML(Object xmlObject) 
    {
      Node item = null;
      SortedMap[] map = null;
      String subchildnodeName = null;
      String subchildnodeValue = null;
      Map subchildmap[] = null;
      try {
          if (xmlObject == null) {
              throw new NullPointerException("XML object found null");
          }
  
          factory = DocumentBuilderFactory.newInstance();
          builder = factory.newDocumentBuilder();
          doc = builder.parse(new ByteArrayInputStream(xmlObject.toString().getBytes()));
          doc.getDocumentElement().normalize();
          node = doc.getDocumentElement();
          root = node.getNodeName();
          nList = doc.getElementsByTagName(root);
  
          for (int temp = 0; temp &lt; nList.getLength(); temp++) {
              nNode = nList.item(temp);
              NodeList childNodes = nNode.getChildNodes();
              int length = childNodes.getLength();
              map = new TreeMap[length];
  
              String nodeValues[][] = new String[length][2];
              for (int i = 0; i &lt; length; i++) {
  
                  item = nNode.getChildNodes().item(i);
                  String parentnodeName = item.getNodeName();
                  int noderepetationlength = doc.getElementsByTagName(parentnodeName).getLength();
                  // System.out.println(noderepetationlength);
                  NodeList rootchildNodes = item.getChildNodes();
                  String parentnodeValue = rootchildNodes.item(0).getNodeValue();
                  map[i] = new TreeMap();
                  if (parentnodeName != null &amp;&amp; parentnodeValue != null &amp;&amp; noderepetationlength &lt;= 1) {
                      map[i].put(parentnodeName, parentnodeValue);
                  } else 
                  {
                      subchildmap = new HashMap[noderepetationlength];
                      for (int t = 0; t &lt; noderepetationlength; t++) 
                      {
  
                          NodeList childNodes1 = item.getChildNodes();
                          int length1 = childNodes1.getLength();
                           subchildmap[t] = new HashMap(); 
                          for (int j = 0; j &lt; length1; j++) 
                          {
  
                              Node item2 = childNodes1.item(j);
                              if (item2.getNodeType() == Node.ELEMENT_NODE) 
                              {
                                  subchildnodeName = item2.getNodeName();
                                  NodeList childNodes2 = item2.getChildNodes();
                                  int length2 = childNodes2.getLength();
                                  for (int k = 0; k &lt; length2; k++) 
                                      subchildnodeValue = childNodes2.item(k).getNodeValue();
  
                              }
                              subchildmap[t].put(subchildnodeName, subchildnodeValue);
  
                          }
                          map[i].put(parentnodeName, subchildmap[t]);
                      }
                  }
              }//else
          } //end of for-loop
  
      } catch (ParserConfigurationException pce) {
      } catch (NullPointerException nofe) {
      } catch (SAXException saxException) {
      } catch (IOException ioe) {
      }
  
      return map;
  } 
  </code></pre>
  
  <p>but not able to get expect results.</p>
  
  <p>Thanks</p>