Created
May 26, 2020 19:50
-
-
Save ssullivan/dd0251f47f8017f8dcfd8a098d3c0637 to your computer and use it in GitHub Desktop.
XSD Validation Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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