programming-examples/java/XML/Simple sax handler.java

49 lines
1.5 KiB
Java
Raw Normal View History

2019-11-15 12:59:38 +01:00
Simple sax handler
package com.ack.xml.jaxp;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
public class SimpleSaxHandler extends DefaultHandler {
public void endDocument() throws org.xml.sax.SAXException {
log( "finished parsing document" );
}
public void startDocument() throws org.xml.sax.SAXException {
log( "starting to parse document" );
}
public void warning( SAXParseException exception ) throws SAXException {
log( "Warning SAX Exception:" +
"\nProblem at line " + exception.getLineNumber() +
", column " + exception.getColumnNumber() +
"\nReason: " + exception.getMessage() );
}
public void error( SAXParseException exception ) throws SAXException {
log( "Error SAX Exception:" +
"\nProblem at line " + exception.getLineNumber() +
", column " + exception.getColumnNumber() +
"\nReason: " + exception.getMessage() );
}
public void fatalError( SAXParseException exception ) throws SAXException {
log( "Fatal Error SAX Exception:" +
"\nProblem at line " + exception.getLineNumber() +
", column " + exception.getColumnNumber() +
"\nReason: " + exception.getMessage() );
}
private void log( String msg ) {
System.out.println( "\n======================" );
System.out.println( msg );
System.out.println( "======================" );
}
}