Making a Parser Example


import org.xml.sax.*;
import org.xml.sax.helpers.*;


public class ParserMaker {

  public static void main(String[] args) {
     
    Parser parser;
    try {
     parser = ParserFactory.makeParser();
    }
    catch (Exception e) {
      try {
        parser = ParserFactory.makeParser(args[0]);
      }
      catch (Exception ee) {
        // fall back on Xerces parser by name
        try {
          parser 
           = ParserFactory.makeParser("org.apache.xerces.parsers.SAXParser");
        }
        catch (Exception eee) {
          System.err.println("Couldn't locate a SAX parser");
          return;          
        }
      }
    }
    
    // Let's see what we ended up with...
    System.out.println(parser.getClass());
    
    // start parsing...   
  
  
  }

}

Previous | Next | Top | Cafe con Leche

Copyright 2000 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified February 12, 2000