code: public void validateWithXmlSchema(String filename, String xmlSchemaPath) throws IOException {
      try (InputStream xmlStream = this.getClass().getResourceAsStream(filename)) {
        if (xmlStream == null) {
          throw new IOException("File not found in classpath: " + filename);
        }
        URL schemaUrl = this.getClass().getResource(xmlSchemaPath);
        if (schemaUrl == null) {
          throw new IOException("XML schema not found in classpath: " + xmlSchemaPath);
        }
        validateInternal(new StreamSource(xmlStream), schemaUrl);
      } catch (Exception e) {
        throw new IOException("Cannot load or parse '" + filename + "'", e);
      }
    }
docs: Validate XML file using the given XSD. Throws an exception on error.
  @param filename File in classpath to validate
  @param xmlSchemaPath XML schema file in classpath