Home  XML introduction

Search this site:
Threads Database Profiling Regular expressions Random numbers Compression Exceptions C Equivalents in Java
 Got a question about Java? Java discussion forum

Parsing XML with SAX: creating a DefaultHandler

In our SAX introduction, we mentioned that we need to override the DefaultHandler class. This class contains (overridable) methods that will be called when various events occur during parsing, principally when parsing reaches start and end tags, and when it has pulled out the text or contents of a tag.

A typical skeleton handler would look as follows:

public class MyHandler extends DefaultHandler {
  public void startElement (String uri, String localName,
  			          String qName, Attributes attributes)
                              throws SAXException {
    ...
  }
  public void endElement (String uri, String localName,
  			        String qName, Attributes attributes)
                              throws SAXException {
    ...
  }
  public void characters (char ch[], int start, int length)
	throws SAXException {
    ...
  }
}
 Did this article answer your question? If not, visit the new Javamex discussion forums to ask your question.


Unless otherwise stated, the Java programming articles and tutorials on this site are written by Neil Coffey. Suggestions are always welcome if you wish to suggest topics for Java tutorials or programming articles, or if you simply have a programming question that you would like to see answered on this site. Most topics will be considered. But in particular, the site aims to provide tutorials and information on topics that aren't well covered elsewhere, or on Java performance information that is poorly described or understood. Suggestions may be made via the Javamex blog (see the site's front page for details).
Copyright © Javamex UK 2009. All rights reserved.