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();
    }
}

相关文章

引言 NOKIA 有句著名的广告语:“科技以人为本”。任何技术都是为了满足人的生产生活需要而产生的。具体...
Writer:BYSocket(泥沙砖瓦浆木匠) 微博:BYSocket 豆瓣:BYSocket Reprint it anywhere u want. 文章...
Writer:BYSocket(泥沙砖瓦浆木匠) 微博:BYSocket 豆瓣:BYSocket Reprint it anywhere u want. 文章...
http://blog.jobbole.com/79252/ 引言 NOKIA 有句著名的广告语:“科技以人为本”。任何技术都是为了满...
(点击上方公众号,可快速关注) 公众号:smart_android 作者:耿广龙|loonggg 点击“阅读原文”,可查看...
一、xml与xslt 相信所有人对xml都不陌生,其被广泛的应用于数据数据传输、保存与序列化中,是一种极为强...