Handler bases

When the application only needs to do something very simple with the XML source data, implementing all the interfaces described above may seem like too much effort. It would be useful if there were a ready-made class that implemented all the interfaces, providing some sensible default behaviour for each event, which could be subclassed to add application-specific functionality.

The SAX API therefore includes a class called HandlerBase that does just this. However, it is still necessary to locate and activate the parser, and pass this class to the parser as the handler of the various interfaces.

Note that in SAX 2.0, while this class is still available, it is superseded by the DefaultHandler class.

Example

The following example demonstrates a very simple application that just reads processing instructions and presents their contents. This application ignores all other events, and assumes that the underlying base handler will do sensible things when they are encountered:

import org.xml.sax.HandlerBase;
...
public class myHandler extends HandlerBase( ) {
{
  public void myHandler()
  {
    ...
  }

  public void processingInstruction(String target,
                                    String content)
  {
    System.out.println( target + "	" + content );
  }
}

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.6.75