XSD检验报文是否符合设计

来源:互联网 发布:c语言的软件是什么 编辑:程序博客网 时间:2024/06/02 05:06
/** * 检验报文是否符合设计 * @param f_xsd 设计文档 * @param file 报文 * @return false 校验不通过 * @throws Exception */public static boolean testXmlBySchema(String f_xsd,File file) throws Exception{DOMParser parser = new DOMParser();parser.setFeature("http://xml.org/sax/features/validation", true);parser.setFeature("http://apache.org/xml/features/validation/schema", true);parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking",true);parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage","http://www.w3.org/2001/XMLSchema");parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource",f_xsd);MyErrorHandler errorHandler = new MyErrorHandler();parser.setErrorHandler(errorHandler);parser.parse(file.getPath());if (errorHandler.getErrors() != null) {return false;} else {return true;}}其中 inputStream = new FileInputStream(file);String f_xsd = "D:\test.xsd";

0 0
原创粉丝点击