title: How can I get parent node while i using SAX parser?
body: <p>I need to parse document using SAX parser in java. I was able to print all the node values if I use DefaultHandler class traditionally implementing the startElement, endElement and  characters method. How can we access the the previous node value at child node, how can I do that?<br>
  My Sample XML is:</p>
  
  <pre><code>&lt;staff&gt;
          &lt;firstname&gt;yong&lt;/firstname&gt;
          &lt;lastname&gt;mook kim&lt;/lastname&gt;
          &lt;nickname&gt;mkyong&lt;/nickname&gt;
          &lt;salary&gt;100000&lt;/salary&gt;
      &lt;/staff&gt;
      &lt;staff&gt;
          &lt;firstname&gt;low&lt;/firstname&gt;
          &lt;lastname&gt;yin fong&lt;/lastname&gt;
          &lt;nickname&gt;fong fong&lt;/nickname&gt;
          &lt;salary&gt;200000&lt;/salary&gt;
      &lt;/staff&gt;
  </code></pre>
  
  <p>Based on salary node value, I also want to access the first name. I am confused. How can we do it? My sample Code:</p>
  
  <pre><code>SAXParserFactory factory = SAXParserFactory.newInstance();
      SAXParser saxParser = factory.newSAXParser();
  
      DefaultHandler handler = new DefaultHandler() {
  
      boolean bfname = false;
      boolean blname = false;
      boolean bnname = false;
      boolean bsalary = false;
  
      public void startElement(String uri, String localName,String qName, 
                  Attributes attributes) throws SAXException {
  
          System.out.println("Start Element :" + qName);
  
          if (qName.equalsIgnoreCase("FIRSTNAME")) {
              bfname = true;
          }
  
          if (qName.equalsIgnoreCase("LASTNAME")) {
              blname = true;
          }
  
          if (qName.equalsIgnoreCase("NICKNAME")) {
              bnname = true;
          }
  
          if (qName.equalsIgnoreCase("SALARY")) {
              bsalary = true;
          }
  
      }
  
      public void endElement(String uri, String localName,
          String qName) throws SAXException {
  
          System.out.println("End Element :" + qName);
  
      }
  
      public void characters(char ch[], int start, int length) throws SAXException {
  
          if (bfname) {
              System.out.println("First Name : " + new String(ch, start, length));
              bfname = false;
          }
  
          if (blname) {
              System.out.println("Last Name : " + new String(ch, start, length));
              blname = false;
          }
  
          if (bnname) {
              System.out.println("Nick Name : " + new String(ch, start, length));
              bnname = false;
          }
  
          if (bsalary) {
              //System.out.println("Salary : " + new String(ch, start, length));
                      String nodeValue=new String(ch, start, length);
                      if(nodeValue.compareTo("100000")==0)
                     {
                       **????I need to store the respective respective first name
                           in ArrayList**
                      }
              bsalary = false;
          }
  
      }
  
       };
  </code></pre>