title: Parsing Xml with SAX Parser
body: <p>I am trying to parse an xml file with SAX Parser. 
  I need to get attributes and it's values of a start element</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
  &lt;API type="Connection"&gt;
  &lt;INFO server="com.com" function="getAccount2" /&gt;
  &lt;RESULT code="0"&gt;Operation Succeeded&lt;/RESULT&gt;
  &lt;RESPONSE numaccounts="1"&gt;
  &lt;ACCOUNT login="fa051981" skynum="111111" maxaliases="1" creationdate="Fri Nov 16 00:59:59 2001"    password="pass" type="2222" status="open" mnemonic="32051981" ratelimit="0"&gt;
      &lt;CHECKATTR /&gt;
      &lt;REPLYATTR&gt;Service-Type = Frames-User, Framed-Protocol = PPP, Framed-Routing = None&lt;/REPLYATTR&gt;
      &lt;SETTINGS bitval="4" status="open" /&gt;
      &lt;SETTINGS bitval="8192" status="open" session_timeout="10800" /&gt;
      &lt;SETTINGS bitval="32768" status="open" cisco_address_pool="thepool" /&gt;
      &lt;ALIASES numaliases="0" /&gt;
  &lt;/ACCOUNT&gt;
  &lt;/RESPONSE&gt;
  &lt;/API&gt;
  </code></pre>
  
  <p>IN this xml, I need to get Settings tag/start element attributes along with it's values.</p>
  
  <p>These attributes are dynamic, so I am trying to make a map of them. I am new to SAX Parser.</p>
  
  <p>So far my java code:</p>
  
  <pre><code>public void startElement(String s, String s1, String elementName, Attributes attributes) throws SAXException {
  
      if (elementName.equalsIgnoreCase(GenericConstants.INFO)) {
          this.searchRaidusBean.setServer(attributes.getValue(GenericConstants.SERVER));
          this.searchRaidusBean.setFunction(attributes.getValue(GenericConstants.FUNCTION));
      }
      if (elementName.equalsIgnoreCase(GenericConstants.RESULT)) {
          this.searchRaidusBean.setResultCode(attributes.getValue(GenericConstants.CODE));
      }
  
      if (elementName.equalsIgnoreCase(GenericConstants.ACCOUNT)) {
          this.searchRaidusBean.setLoginId(attributes.getValue(GenericConstants.LOGIN));
      }
      if (elementName.equalsIgnoreCase(GenericConstants.ACCOUNT)) {
          this.searchRaidusBean.setSkyNum(attributes.getValue(GenericConstants.SKYNUM));
      }
      if (elementName.equalsIgnoreCase(GenericConstants.ACCOUNT)) {
          this.searchRaidusBean.setMaxAliases(attributes.getValue(GenericConstants.MAXALIASES));
      }
      if (elementName.equalsIgnoreCase(GenericConstants.ACCOUNT)) {
          this.searchRaidusBean.setCreationDate(attributes.getValue(GenericConstants.CREATION_DATE));
      }
      if (elementName.equalsIgnoreCase(GenericConstants.ACCOUNT)) {
          this.searchRaidusBean.setType(attributes.getValue(GenericConstants.TYPE));
      }
      if (elementName.equalsIgnoreCase(GenericConstants.ACCOUNT)) {
          this.searchRaidusBean.setStatus(attributes.getValue(GenericConstants.STATUS));
      }
      if (elementName.equalsIgnoreCase(GenericConstants.ACCOUNT)) {
          this.searchRaidusBean.setMnemonic(attributes.getValue(GenericConstants.MNEMONIC));
      }
      if (elementName.equalsIgnoreCase(GenericConstants.ACCOUNT)) {
          this.searchRaidusBean.setRateLimit(attributes.getValue(GenericConstants.RATELIMIT));
      }
      if (elementName.equalsIgnoreCase(GenericConstants.SETTINGS)) {
          //this.searchRaidusBean.getBitval().add(attributes.getValue(GenericConstants.BITVAL));
          System.out.println(attributes);
          //stuck here
      }
      if (elementName.equalsIgnoreCase(GenericConstants.ALIASES)) {
          this.tempKey = attributes.getValue(GenericConstants.MNEMONIC);
      }
  }
  
  
  
  public void endElement(String str1, String str2, String element) throws SAXException {
      if (element.equalsIgnoreCase(GenericConstants.RESULT)) {
          this.searchRaidusBean.setResultMessage(this.tempValue);
      }
      if (element.equalsIgnoreCase(GenericConstants.ALIASES)) {
          if (!StringUtils.isBlank(this.tempKey)) {
              this.searchRaidusBean.getAlias().put(this.tempKey, this.tempValue);
          }
      }
  }
  
  
  public void characters(char[] charArray, int i, int j) throws SAXException {
      this.tempValue = new String(charArray, i, j);
  }
  </code></pre>