首页 > 代码库 > Java SAX Schema Validation
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.
Java SAX Schema Validation
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。