title: using SAX parser, how do you parse an xml file which has same name tags but in different elements?
body: <p>Is it possible to give path expressions in SAX parser? I have an XML file which has a few same name tags, but they are in different element. Is there any way to differentiate between them.
  Here is the XML:</p>
  
  <pre><code>&lt;Schools&gt;
      &lt;School&gt;
          &lt;ID&gt;335823&lt;/ID&gt; 
          &lt;Name&gt;Fairfax High School&lt;/Name&gt; 
          &lt;Student&gt;
              &lt;ID&gt;4195653&lt;/ID&gt;
              &lt;Name&gt;Will Turner&lt;/Name&gt;
          &lt;/Student&gt;
          &lt;Student&gt;
              &lt;ID&gt;4195654&lt;/ID&gt;
              &lt;Name&gt;Bruce Paltrow&lt;/Name&gt;
          &lt;/Student&gt;
          &lt;Student&gt;
              &lt;ID&gt;4195655&lt;/ID&gt;
              &lt;Name&gt;Santosh Gowswami&lt;/Name&gt;
          &lt;/Student&gt;
      &lt;/School&gt;
      &lt;School&gt;
          &lt;ID&gt;335824&lt;/ID&gt; 
          &lt;Name&gt;FallsChurch High School&lt;/Name&gt; 
          &lt;Student&gt;
              &lt;ID&gt;4153&lt;/ID&gt;
              &lt;Name&gt;John Singer&lt;/Name&gt;
          &lt;/Student&gt;
          &lt;Student&gt;
              &lt;ID&gt;4154&lt;/ID&gt;
              &lt;Name&gt;Shane Warne&lt;/Name&gt;
          &lt;/Student&gt;
          &lt;Student&gt;
              &lt;ID&gt;4155&lt;/ID&gt;
              &lt;Name&gt;Eddie Diaz&lt;/Name&gt;
          &lt;/Student&gt;
      &lt;/School&gt;
  &lt;/Schools&gt;
  </code></pre>
  
  <p>I want to differentiate between the Name and Id of a student from the name and ID of a school. </p>
  
  <p>Thanks for the response:</p>
  
  <p>I have created a student pojo which has the following fields- school_id,school_name, student_id and student_name and getter and setter methods for them. This is my temporary parser implementation. When i parse the xml, I need to put the values of school name, id , student name, id in the pojo and return it. Can you tell me on how I should  implement the stack for the differentiation. This is my parser framework::</p>
  
  <pre><code>import org.xml.sax.Attributes;
  import org.xml.sax.SAXException;
  import org.xml.sax.helpers.DefaultHandler;
  
  public class HandleXML extends DefaultHandler {
  
      private student info;
      private boolean school_id = false;
      private boolean school_name = false;
      private boolean student_id = false;
      private boolean student_name = false;
      private boolean student = false;
      private boolean school = false;
  
  
      public HandleXML(student record) {
          super();
          this.info = record;
          school_id = false;
          school_name = false;
          student_id = false;
          student_name = false;
          student = false;
          school = false;
      }
  
      @Override
      public void startElement(String uri, String localName,
              String qName, Attributes attributes)
              throws SAXException {
      if (qName.equalsIgnoreCase("student")) {
              student = true;
          }
      if (qName.equalsIgnoreCase("school")) {
              school_id = true;
          }
      if (qName.equalsIgnoreCase("school_id")) {
              school_id = true;
          }
      if (qName.equalsIgnoreCase("student_id")) {
              student_id = true;
          }
      if (qName.equalsIgnoreCase("school_name")) {
              school_name = true;
          }
      if (qName.equalsIgnoreCase("student_name")) {
              student_name = true;
          }
      }
  
      @Override
      public void endElement(String uri, String localName,
              String qName)
              throws SAXException {
      }
  
      @Override
      public void characters(char ch[], int start, int length)
              throws SAXException {
  
          String data = new String(ch, start, length);
  
      }
  }
  </code></pre>