title: Split XML using SAX parser
body: <p>I have following xml file.</p>
  
  <pre><code>&lt;Engineers&gt;
      &lt;Engineer&gt;
          &lt;Name&gt;JOHN&lt;/Name&gt;
          &lt;Position&gt;STL&lt;/Position&gt;
          &lt;Team&gt;SS&lt;/Team&gt;
      &lt;/Engineer&gt;
      &lt;Engineer&gt;
          &lt;Name&gt;UDAY&lt;/Name&gt;
          &lt;Position&gt;TL&lt;/Position&gt;
          &lt;Team&gt;SG&lt;/Team&gt;
      &lt;/Engineer&gt;
      &lt;Engineer&gt;
          &lt;Name&gt;INDRA&lt;/Name&gt;
          &lt;Position&gt;Director&lt;/Position&gt;
          &lt;Team&gt;PP&lt;/Team&gt;
      &lt;/Engineer&gt;
  &lt;/Engineers&gt;
  </code></pre>
  
  <p>I need to split this xml into smaller xml strings when Xpath is given as Engineers/Enginner.</p>
  
  <p>Smaller xml strings are as follows</p>
  
  <pre><code>&lt;Engineers&gt;
      &lt;Engineer&gt;
          &lt;Name&gt;INDRA&lt;/Name&gt;
          &lt;Position&gt;Director&lt;/Position&gt;
          &lt;Team&gt;PP&lt;/Team&gt;
      &lt;/Engineer&gt;
  &lt;/Engineers&gt;
  
  &lt;Engineers&gt;
      &lt;Engineer&gt;
          &lt;Name&gt;JOHN&lt;/Name&gt;
          &lt;Position&gt;STL&lt;/Position&gt;
          &lt;Team&gt;SS&lt;/Team&gt;
      &lt;/Engineer&gt;
  &lt;/Engineers&gt;
  </code></pre>
  
  <p>I have implemented following so far using SAX which we can get the elements inside XML but not as what I want.How can I proceed??</p>
  
  <pre><code>public class ReadSAX
  {
      public static void main( String[] args )
      {
          try {
  
                SAXParserFactory factory = SAXParserFactory.newInstance();
                SAXParser saxParser = factory.newSAXParser();
  
                DefaultHandler handler = new DefaultHandler() {
  
     public void startElement(String uri, String localName,
                      String qName, Attributes attributes)
                      throws SAXException {
  
                    System.out.println("Start Element :" + qName);
  
  
  
                  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 {
  
                    System.out.println(new String(ch, start, length));
  
  
                   }
  
                };
  
                File file = new File("c:\\file.xml");
                InputStream inputStream= new FileInputStream(file);
                Reader reader = new InputStreamReader(inputStream,"UTF-8");
  
                InputSource is = new InputSource(reader);
                is.setEncoding("UTF-8");
  
                saxParser.parse(is, handler);
  
  
              } catch (Exception e) {
                e.printStackTrace();
              }
  
      }
  }
  </code></pre>