Вы можете использовать API javax.xml.validation для этого.
public boolean validate(String inputXml, String schemaLocation)
throws SAXException, IOException {
// build the schema
SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
File schemaFile = new File(schemaLocation);
Schema schema = factory.newSchema(schemaFile);
Validator validator = schema.newValidator();
// create a source from a string
Source source = new StreamSource(new StringReader(inputXml));
// check input
boolean isValid = true;
try {
validator.validate(source);
}
catch (SAXException e) {
System.err.println("Not valid");
isValid = false;
}
return isValid;
}