code: public void validateModel(DomDocument document) {
  
      Schema schema = getSchema(document);
  
      if (schema == null) {
        return;
      }
  
      Validator validator = schema.newValidator();
      try {
        synchronized(document) {
          validator.validate(document.getDomSource());
        }
      } catch (IOException e) {
        throw new ModelValidationException("Error during DOM document validation", e);
      } catch (SAXException e) {
        throw new ModelValidationException("DOM document is not valid", e);
      }
    }
docs: Validate DOM document
  
  @param document the DOM document to validate