Jsp My Titles6Java

From Fxp Wiki

Jump to: navigation, search
 
package vendo;
 
import org.apache.xerces.parsers.SAXParser;
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
import java.io.*;
import java.util.*;
 
public class MyTitles6 extends DefaultHandler {
 
private Writer out;
	String monfile;
boolean local0 = false;
int counter=0;
String[] result = new String[12];
String[] inpt = new String[12];
String[] outp = new String[12];
	// constructor
    	public MyTitles6 (String xmlFile, Writer out) {
 
        		this.out = out;
		monfile = xmlFile;
        		//  create a Xerces SAX parser
        		SAXParser parser = new SAXParser();
 
        		//  set the content handler
        		parser.setContentHandler(this);
        		//  parse the document
        		try {
            			parser.parse(xmlFile);
			out.flush();
        		} catch (IOException e) {
            			// something went wrong!
        		}
			catch (SAXException e) {
            			// something went wrong!
        		}
    	}
 
	// call at document start
	public void startDocument() {
 
		try {
			out.write ("<h3>" + monfile + " 3</h3>");
		}
		catch (IOException e) {
                               			 System.err.println(" You generated an exception 1 :" +e);
			} 
 
	}
 
	// call at element start
    	public void startElement (String uri, String local, String qName,
Attributes atts) throws SAXException {
 
		try {
			out.write ("<p>" + qName + "<br />" );
			counter++;
			//throw new SAXException("finished");
		} catch (IOException e) {
			 System.err.println(" You generated an exception 2 :" +e);
			}
	}
	// call when cdata found
    	public void characters(char[] text, int start, int length) {
 
		try {
			String Content = new String(text, start, length);
			out.write ("<br /><b>Content</b> :" + Content );
		} catch (IOException e) {
			System.err.println(" You generated an exception 3 :" +e);
		}
    	}
 
	// call at element end
	public void endElement (String uri, String local, String qName) {
		try {
			out.write ("Div3" );
		} catch (IOException e) {
				System.err.println(" You generated an exception 4: " +e);
		}
	}
 
	// call at document end
	public void endDocument() {
		try {
			out.write ("Div4" );
		} catch (IOException e) {
			System.err.println(" You generated an exception 5: " +e);
		}
	}
}
 
 
Personal tools