How to create XML validator from XML schema?

How to create XML validator from XML schema?

public static void main(String[] args) throws Exception {
    // http://www.java-tips.org/java-se-tips-100019/170-javax-xml-validation/1733-how-to-create-xml-validator-from-xml-schema.html
    try {
        // define the type of schema - we use W3C:
        String schemaLang = XMLConstants.W3C_XML_SCHEMA_NS_URI;
        // get validation driver:
        SchemaFactory factory = SchemaFactory.newInstance(schemaLang);
        // create schema by reading it from an XSD file:
        Schema schema = factory.newSchema(new StreamSource(
                "BuildInstall.xsd"));
        Validator validator = schema.newValidator();
        // at last perform validation:
        validator.validate(new StreamSource("Install.xml"));

    } catch (SAXException | IOException ex) {
        // we are here if the document is not valid:
        // ... process validation error...
        ex.printstacktrace();
    }
}

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念