Skip to content

Instantly share code, notes, and snippets.

@ssullivan
Created May 26, 2020 19:50
Show Gist options
  • Select an option

  • Save ssullivan/dd0251f47f8017f8dcfd8a098d3c0637 to your computer and use it in GitHub Desktop.

Select an option

Save ssullivan/dd0251f47f8017f8dcfd8a098d3c0637 to your computer and use it in GitHub Desktop.
XSD Validation Java
public static boolean validateXMLSchema(String xsdPath, String xmlPath){
try {
SchemaFactory factory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(new File(xsdPath));
Validator validator = schema.newValidator();
validator.validate(new StreamSource(new File(xmlPath)));
} catch (IOException | SAXException e) {
System.out.println("Exception: "+e.getMessage());
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment