public static void print(String parserName, String uri, boolean validate) {
try {
SAXCount counter = new SAXCount();
Parser parser = ParserFactory.makeParser(parserName);
parser.setDocumentHandler(counter);
parser.setErrorHandler(counter);
try {
if (validate && parser instanceof XMLReader)
((XMLReader)parser).setFeature("http://xml.org/sax/features/validation", true);
} catch (Exception ex) {}
if (warmup) {
if (parser instanceof XMLReader)
((XMLReader)parser).setFeature("http://apache.org/xml/features/continue-after-fatal-error", true);
parser.parse(uri);
warmup = false;
}
long before = System.currentTimeMillis();
parser.parse(uri);
long after = System.currentTimeMillis();
counter.printResults(uri, after - before);
}
catch (org.xml.sax.SAXParseException spe) {
spe.printStackTrace(System.err);