title: Parsing XML into a Hashmap Java
body: <p>I have some information stored in XML, and I need to parse XML and store some of the values in Hashmap. 
  Here is the XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  &lt;section ID="1"&gt;
      &lt;Room&gt;Room1&lt;/Room&gt;
      &lt;Capactiy&gt;25&lt;/Capactiy&gt;
      &lt;Approval_Mode&gt;personally&lt;/Approval_Mode&gt;
      &lt;Building&gt;Building1&lt;/Building&gt;
      &lt;Address&gt;Streer, 1. Stock, links&lt;/Address&gt;
      &lt;Room_Number&gt;ZA0115&lt;/Room_Number&gt;
      &lt;CoordLt&gt;16.412094&lt;/CoordLt&gt;
      &lt;CoordLn&gt;48.19719&lt;/CoordLn&gt;
  &lt;/section&gt;
  &lt;section ID="2"&gt;
      &lt;Room&gt;Room2&lt;/Room&gt;
      &lt;Capactiy&gt;120&lt;/Capactiy&gt;
      &lt;Institute&gt;E401&lt;/Institute&gt;
      &lt;Approval_Mode&gt;personally&lt;/Approval_Mode&gt;
      &lt;Building&gt;Building2&lt;/Building&gt;
      &lt;Address&gt;Street 2, Building2, Stiege 7, 1.Stock&lt;/Address&gt;
      &lt;Room_Number&gt;AH0105&lt;/Room_Number&gt;
      &lt;CoordLt&gt;16.369865&lt;/CoordLt&gt;
      &lt;CoordLn&gt;48.199006&lt;/CoordLn&gt;
  &lt;/section&gt;
  ----
  </code></pre>
  
  <p>I want that key be:Room1 and values: 16.412094,48.19719 (example for Section ID=1)</p>
  
  <p>That is example for first section.I have more than 100 section so I would like to store key and values for every section like I explained for the first example.</p>
  
  <p>Output would be:</p>
  
  <p>Room1: 16.412094,48.19719;
  Room2: 16.369865,48.199006;</p>
  
  <p>Room3: 16,48;
  .
  .
  .
  Room100: 16,49;</p>
  
  <p>Can anyone help me?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>import java.io.File; 
  import java.sql.ResultSet;
  import java.util.HashMap; 
  import org.xml.sax.*; 
  import org.xml.sax.helpers.DefaultHandler; 
  import javax.xml.parsers.SAXParserFactory; 
  import javax.xml.parsers.ParserConfigurationException; 
  import javax.xml.parsers.SAXParser; 
  
  public class XML extends DefaultHandler  
  { 
  static HashMap&lt;StringBuffer, String&gt; hashMap; 
  String elementName; 
  StringBuffer elementValue;
  private HashMap&lt;String, String&gt; newMap; 
  public static void main(String[] args) 
  { 
  DefaultHandler handler = new XML(); 
  SAXParserFactory factory = SAXParserFactory.newInstance(); 
  try 
  { 
  hashMap = new HashMap&lt;StringBuffer, String&gt;(); 
  //out = new OutputStreamWriter(System.out, "UTF8"); 
  SAXParser saxParser = factory.newSAXParser(); 
  saxParser.parse(new File("xml1.xml"), handler); 
  System.out.println(hashMap); 
  } 
  catch(Throwable t) 
  { 
  t.printStackTrace(); 
  } 
  System.exit(0); 
  } 
  
  
  public void startElement(String namespaceURI, String sName, String qName, Attributes    attrs) 
  throws SAXException 
  { 
  String eName = sName; 
  if("".equals(eName)) eName = qName;
  
  elementName = eName; 
  if(attrs != null) 
  { 
  for(int i = 0; i &lt; attrs.getLength(); i++) 
  { 
  String aName = attrs.getLocalName(i); 
  if("".equals(aName)) aName = attrs.getQName(i); 
  
  } 
  } 
  } 
  
  public void endElement(String namespaceURI, String sName, String qName) 
  throws SAXException 
  
  { 
  String eName = sName; 
  if("".equals(eName)) eName = qName; 
  
  if(eName.equals(elementName)) 
  
  hashMap.put(elementValue,""+ elementName );
  elementValue = null;  
  } 
  
  public void characters(char[] ch, int start, int length) 
  throws SAXException 
  { 
  String str = new String(ch, start, length); 
  if(elementValue == null) 
  elementValue = new StringBuffer(str); 
  else 
  elementValue.append(str); 
  } 
  }
  </code></pre>
  
  <p>With this code I don't get desired output.
  output is:
  Room=Room1, Capacity=25......</p>