• Java SAX Schema Validation


    It is possible to turn on XML Schema validation during parsing with a SAXParser. Here is how it looks:

    Schema schema = null;
    try {
      String language = XMLConstants.W3C_XML_SCHEMA_NS_URI;
      SchemaFactory factory = SchemaFactory.newInstance(language);
      schema = factory.newSchema(new File(name));
    } catch (Exception e) {
        e.printStackStrace();
    }
    
    
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setSchema(schema);
    
    SAXParser parser = spf.newSAXParser();
    
    parser.parse(...);

    First a Schema object is created from some XML schema file.

    Second, a SAXParserFactory is created and this factory has the Schema instance set on it. All SAXParser instances created by this factory will use this XML Schema to validate XML files.

    Third, an XML file is parsed and validated.

  • 相关阅读:
    第二次作业——App案例分析
    第一次作业--四则运算
    一点感想
    结对编程1
    第二次作业
    第一次作业-四则运算
    我的第一篇博客
    第二次作业
    结对编程
    第二次作业 APP分析
  • 原文地址:https://www.cnblogs.com/ghgyj/p/4017968.html
Copyright © 2020-2023  润新知