package ml.ml;

import java.io.InputStream;
import java.util.ArrayList;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;


public class ExampleHandler extends DefaultHandler {

 // ===========================================================
 // Fields
 // ===========================================================

 private boolean in_hltag = false;
 private boolean in_sltag = false;
 private boolean in_name = false;
 private boolean in_path = false;
 private boolean in_model= false;
 private boolean in_spec = false;
 private boolean in_imageList = false;
 private boolean in_videoList = false;
 
 private xmlTag xmlTag;
 private Subchild Subchild;
 private schild modelChild;

 public ParsedExampleDataSet myParsedExampleDataSet = new ParsedExampleDataSet();


 // ===========================================================
 // Getter & Setter
 // ===========================================================

 public ParsedExampleDataSet getParsedData() {
  return this.myParsedExampleDataSet;
 }

 // ===========================================================
 // Methods
 // ===========================================================
 @Override
 public void startDocument() throws SAXException {
  this.myParsedExampleDataSet = new ParsedExampleDataSet();
 }

 @Override
 public void endDocument() throws SAXException {
  // Nothing to do
 }

 /** Gets be called on opening tags like: 
  * <tag> 
  * Can provide attribute(s), when xml was like:
  * <tag attribute="attributeValue">*/
 @Override
 public void startElement(String namespaceURI, String localName,
   String qName, Attributes atts) throws SAXException {
  if (localName.equals("hltag")) {
   xmlTag = new xmlTag();
   //String hltagattr=atts.getValue("name");
   this.in_hltag = true;
  }else if (localName.equals("sltag")) {
   Subchild = new Subchild();
   //String hltagattr=atts.getValue("name");
   //String hlatgattr=atts.getValue("path");
   this.in_sltag = true;
  }else if (localName.equals("name")){
   this.in_name = true;
  }else if (localName.equals("path")){
   this.in_path = true;
  }else if (localName.equals("model")){
   modelChild = new schild();
   this.in_model =true;
  }else if(localName.equals("spec")){
   this.in_spec =true;
  }else if(localName.equals("imageList")){
   this.in_imageList =true;
  }else if(localName.equals("videoList")){
   this.in_videoList =true;
  }
 }

 /** Gets be called on closing tags like: 
  * </tag> */
 @Override
 public void endElement(String namespaceURI, String localName, String qName)
 throws SAXException {
  if (localName.equals("hltag")) {
   myParsedExampleDataSet.AddNewHltag(xmlTag);
   this.in_hltag = false;
  }else if (localName.equals("sltag")) {
   xmlTag.addSlTag(Subchild);
   this.in_sltag = false;
  }else if (localName.equals("name")){
   this.in_name = false;
  }else if(localName.equals("path")){
   this.in_path = false;
   
  }else if (localName.equals("model")){
   Subchild.addModelTag(modelChild);
   this.in_model =false;
  }else if(localName.equals("spec")){
   this.in_spec =false;
  }else if(localName.equals("imageList")){
   this.in_imageList =false;
  }else if(localName.equals("videoList")){
   this.in_videoList =false;
     
  }
 }
 
 /** Gets be called on the following structure: 
  * <tag>characters</tag> */
 @Override
 public void characters(char ch[], int start, int length) {
  if(this.in_model && this.in_name){
   String ModName = new String(ch, start, length);
   modelChild.name = ModName;
  }else if(this.in_sltag && this.in_name){
  // xmlTag.sltag.add(new String(ch, start, length));
   String SltagName = new String(ch, start, length);
   Subchild.name = SltagName;
   //myParsedExampleDataSet.setsltag(new Subchild(ch, start, length));
  }else if(this.in_hltag && this.in_name){
   String hltag = new String(ch, start, length);
   xmlTag.hltag = hltag;
   myParsedExampleDataSet.sethltag(new String(ch, start, length));
  }else if(this.in_sltag && this.in_path){
   String SltagPath = new String(ch, start, length);
   Subchild.path = SltagPath;
   //myParsedExampleDataSet.setsltag(new Subchild(ch, start, length));
  }else if(this.in_model && this.in_spec){
   String MSpec = new String(ch, start, length);
   modelChild.spec = MSpec;
  }else if(this.in_model && this.in_imageList){
   String MImage =new String(ch, start, length);
   modelChild.imageList.add(MImage);
  }else if(this.in_model && this.in_videoList){
   String MVideo = new String(ch, start, length);
   modelChild.videoList.add(MVideo);
  }

   

 }
}

Add a code snippet to your website: www.paste.org