// Create a parser factory and use it to create a parser
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
SAXParser parser = parserFactory.newSAXParser();
// This is the name of the file you're parsing
String filename = args[0];
// Instantiate a DefaultHandler subclass to do your counting for you
CountHandler handler = new CountHandler();
// Start the parser. It reads the file and calls methods of the
// handler.
parser.parse(new File(filename), handler);
// When you're done, report the results stored by your handler object
System.out.println(filename + " contains " + handler.numElements +
" elements and " + handler.numChars +
" other characters ");