进阶:看java实现的XMLschema验证
最近对Schema 验证研究了一下, 代码
所需JAR包需要自己下载(版本一定要正确)
public class SchemaValidation {
public static void main(String args) {
}
public static void validate() {
SchemaValidation demo = new SchemaValidation();
InputStream xmlString = demo.getClass().getResourceAsStream("GBAInit.xml");
System.out.println("XSD parse successfully !");
Document document = reader.read(xmlString);
} catch (DocumentException e) {
Throwable nestedException = e.getNestedException();
System.out.println("NestedException: " + nestedException);
} else {
}
System.out.println("Exception occurred: " + t);
}
/** Registers the Verifier with the SAXReader */
System.out.println("Loaded schema document: " + schemaURI);
// use autodetection of schemas
Schema schema = factory.compileSchema(schemaURI);
Verifier verifier = schema.newVerifier();
public void error(SAXParseException e) {
}
public void fatalError(SAXParseException e) {
}
public void warning(SAXParseException e) {
}
// now install the verifying filter
SAXReader reader = new SAXReader();
return reader;
编辑推荐:
温馨提示:因考试政策、内容不断变化与调整,长理培训网站提供的以上信息仅供参考,如有异议,请考生以权威部门公布的内容为准! (责任编辑:长理培训)
点击加载更多评论>>