private static String validarXML(String ruta) {
String cadena = "";
try {
Source schemaFile = new StreamSource(new File("Schema.xsd"));
Source xmlFile = new StreamSource(new File(ruta));
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(schemaFile);
Validator validator = schema.newValidator();
validator.validate(xmlFile);
cadena="OK";
return cadena;
} catch (SAXException e) {
// Documento erróneo
cadena="Error al validarlo.";
File archivo = new File(ruta);
archivo.delete();
System.out.println(e.toString()+"<br>");
} catch (IOException e) {
e.printStackTrace();
}
return cadena;
}
String cadena = "";
try {
Source schemaFile = new StreamSource(new File("Schema.xsd"));
Source xmlFile = new StreamSource(new File(ruta));
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(schemaFile);
Validator validator = schema.newValidator();
validator.validate(xmlFile);
cadena="OK";
return cadena;
} catch (SAXException e) {
// Documento erróneo
cadena="Error al validarlo.";
File archivo = new File(ruta);
archivo.delete();
System.out.println(e.toString()+"<br>");
} catch (IOException e) {
e.printStackTrace();
}
return cadena;
}