private static void checkHtmlFile(File file) throws IOException, Exception {
        try {
            String path = file.getPath();
            if (!file.exists()) {
                if (verbose) {
                    errorHandler.warning(new SAXParseException(
                            "File not found.", null,
                            file.toURI().toURL().toString(), -1, -1));
                }
                return;
            } else if (isXhtml(file)) {
                emitFilename(path);
                if (forceHTML) {
                    validator.checkHtmlFile(file, true);
                } else {
                    if (!"http://s.validator.nu/xhtml5-all.rnc".equals(
                            validator.getMainSchemaUrl()) && !hasSchemaOption) {
                        setSchema("http://s.validator.nu/xhtml5-all.rnc");
                    }
                    validator.checkXmlFile(file);
                }
            } else if (isHtml(file)) {
                emitFilename(path);
                if (forceXML) {
                    if (!"http://s.validator.nu/xhtml5-all.rnc".equals(
                            validator.getMainSchemaUrl()) && !hasSchemaOption) {
                        setSchema("http://s.validator.nu/xhtml5-all.rnc");
                    }
                    validator.checkXmlFile(file);
                } else {
                    if (!"http://s.validator.nu/html5-all.rnc".equals(
                            validator.getMainSchemaUrl()) && !hasSchemaOption) {
                        setSchema("http://s.validator.nu/html5-all.rnc");
                    }
                    validator.checkHtmlFile(file, true);
                }
            } else {
                if (verbose) {
                    errorHandler.warning(new SAXParseException(
                            "File was not checked. Files must have .html,"
                                    + " .xhtml, .htm, or .xht extensions.",
                            null, file.toURI().toURL().toString(), -1, -1));
                }
            }
        } catch (SAXException e) {
            if (!errorsOnly) {
                System.err.printf("\"%s\":-1:-1: warning: %s\n",
                        file.toURI().toURL().toString(), e.getMessage());
            }
        }
    }
Simple command-line validator for HTML/XHTML files.
src/nu/validator/client/SimpleCommandLineValidator.java