code: public void validateStringWithXmlSchema(String xml, String xmlSchemaPath) throws IOException {
      try {
        URL schemaUrl = this.getClass().getResource(xmlSchemaPath);
        if (schemaUrl == null) {
          throw new IOException("XML schema not found in classpath: " + xmlSchemaPath);
        }
        try (ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes("utf-8"))) {
          validateInternal(new StreamSource(stream), schemaUrl);
        }
      } catch (SAXException e) {
        throw new RuntimeException(e);
      }
    }
docs: Validate XML file using the given XSD. Throws an exception on error.
  @param xml the XML string to be validated
  @param xmlSchemaPath XML schema file in classpath
  @since 2.3