1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| public static Vector validateXML(String xmlMessage,String path) {
final Vector errorsList = new Vector();
File f=new File(xmlMessage);
try{
FileInputStream is = new FileInputStream(f);
byte[] attBody = new byte[is.available()];
is.read(attBody);
String msg = new String(attBody);
System.out.println(msg);
InputStream IS = null;
try {
System.out.println("okkk");
IS = new java.io.ByteArrayInputStream(msg.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e1) {e1.printStackTrace();}
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setIgnoringComments(true);
dbf.setNamespaceAware(true);
dbf.setValidating(true);
System.out.println("okkk2");
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);
SAXParser saxParser = null;
try {
System.out.println("okkk3");
saxParser = factory.newSAXParser();
try {
System.out.println("okkk4");
saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
saxParser.setProperty(JAXP_SCHEMA_SOURCE, path);
} catch (SAXNotRecognizedException e) {} catch (SAXNotSupportedException e) {}
} catch (ParserConfigurationException e1) {e1.printStackTrace();
} catch (SAXException e1) {e1.printStackTrace();}
try {
System.out.println("okkk5");
saxParser.parse(IS, new DefaultHandler(){
public void fatalError(SAXParseException e) {
errorsList.add("E516"+e.getMessage()+"");
System.out.println("okkk");
System.out.println(e.getMessage());
isValid=false;
}
public void error(SAXParseException e) {
errorsList.add("E516"+e.getMessage()+"");
System.out.println("okkk1111");
System.out.println(e.getMessage());
isValid=false;
}
public void warning(SAXParseException e) {
errorsList.add("E516"+e.getMessage()+"");
System.out.println("okkk22222222222");
System.out.println(e.getMessage());
isValid=false;
}
});
} catch (IOException ioe) {
System.out.println(ioe);
} catch (SAXException saxe) {
System.out.println(saxe);
isValid=false;}
/*}
else
{errorsList.add("E514"+""+"");}*/
/*}
else {System.out.println("E515 jok");errorsList.add(new gdpError("E515","",""));}
*/
}catch(Exception e){System.out.println(e.getMessage());}
System.out.println(isValid);
return errorsList;
} |
Partager