public static boolean Validatexml(String xsdpath,String xmlpath)
throws SAXException,IOException{
SchemaFactory schemaFactory=SchemaFactory.newInstance(
"http://www.w3.org/2001/XMLSchema");
File schemaFile=
new File(xsdpath);
Schema schema=schemaFactory.newSchema(schemaFile);
Validator validator=schema.newValidator();
Source source=
new StreamSource(xmlpath);
try{
validator.validate(source);
}
catch(Exception ex){
ex.printStackTrace();
return false;
}
return true;
}
所需文件 http://download.csdn.net/my
测试类
boolean judge = Validatexml(xsdPath,xmlPath);
System.
out.println(judge);
}
catch (SAXException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
转载请注明原文地址: https://ju.6miu.com/read-19568.html