private static void validate(Document doc, String schemaLocation) throws SAXException {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// root element has namespace - we can use schema validation
Schema schema = factory.newSchema(new StreamSource(FeatureValidationUtil.class.getResourceAsStream(schemaLocation)));
// create schema by reading it from an XSD file:
Validator validator = schema.newValidator();
try {
validator.validate(new DOMSource(doc));
} catch (Exception e) {
throw new IllegalArgumentException("Unable to validate " + doc.getDocumentURI(), e);
}