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
968574
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);
    }
  }
1019966
public void validate(String path, Schema schema, Object value, List<ValidationResult> results) {
		String name = path != null ? path : "value";

		if (!ObjectComparator.compare(value, _operation, _value)) {
			results.add(new ValidationResult(path, ValidationResultType.Error, "BAD_VALUE",
					name + " must " + _operation + " " + _value + " but found " + value, _operation + " " + _value,
					value));
		}
	}
909699
public void validate(final Node document) throws SchemaValidationException
	{
		try
		{
			final Validator validator = schema.newValidator();

			validator.validate(new DOMSource(document));
		}
		catch (SAXException | IOException e)
		{
			throw new SchemaValidationException(e.getMessage(), e);
		}
	}
712447
public static XmlPath parse(String xmlPathQuery) {
        // validations
        if(xmlPathQuery == null) {
            throw new XmlPathException("The XML path query can not be a null value");
        }
        xmlPathQuery = xmlPathQuery.trim();

        // simple patterns
        if(! xmlPathQuery.contains("/")) {
            if("*".equals(xmlPathQuery)) {
                return new XmlPath(new XmlPathAnyElement());
            } else if("@*".equals(xmlPathQuery)) {
                return new XmlPath(new XmlPathAnyAttributeElement());
            } else if("node()".equals(xmlPathQuery)) {
                return new XmlPath(new XmlPathAnyNode());
            } else if(xmlPathQuery.matches(XmlPathNodenameAttribute.REGEX_MATCH)) {
                return new XmlPath(new XmlPathNodenameAttribute(xmlPathQuery));
            } else if(xmlPathQuery.matches(XmlPathNodename.REGEX_MATCH)) {
                return new XmlPath(new XmlPathNodename(xmlPathQuery));
            }
        }

        // sub-tree patterns
        Matcher m = rePath.matcher(xmlPathQuery);
        if(! m.matches()) {
            throw new XmlPathException("Invalid xml path query: " + xmlPathQuery);
        }

        XmlPath.Builder builder = XmlPath.builder();
        m = rePathPart.matcher(xmlPathQuery);
        while(m.find()) {
            String part = m.group(1);
            if("*".equals(part)) {
                builder.add(new XmlPathAnyElement());
            } else if("@*".equals(part)) {
                builder.add(new XmlPathAnyAttributeElement());
            } else if("node()".equals(part)) {
                builder.add(new XmlPathAnyNode());
            } else if(part.matches(XmlPathNodenameAttribute.REGEX_MATCH)) {
                builder.add(new XmlPathNodenameAttribute(part));
            } else if (part.matches(XmlPathNodename.REGEX_MATCH)) {
                builder.add(new XmlPathNodename(part));
            } else {
                throw new XmlPathException("Invalid part(" + part + ") in xml path query: " + xmlPathQuery);
            }
        }
        return builder.construct();
    }
1030373
private void validateXMLSchema(InputStream objectAsStream, DOValidatorXMLSchema xsv)
            throws ObjectValidityException, GeneralException {

        try {
            xsv.validate(objectAsStream);
        } catch (ObjectValidityException e) {
            logger.error("VALIDATE: ERROR - failed XML Schema validation.", e);
            throw e;
        } catch (Exception e) {
            logger.error("VALIDATE: ERROR - failed XML Schema validation.", e);
            throw new ObjectValidityException("[DOValidatorImpl]: validateXMLSchema. "
                    + e.getMessage());
        }
        logger.debug("VALIDATE: SUCCESS - passed XML Schema validation.");
    }
955143
private void _reportWarning(XMLReporter rep, String probType, String msg,
                               Location loc)
        throws XMLStreamException
    {
        if (rep != null) {
            /* Note: since the problem occurs at DTD (schema) parsing,
             * not during validation, can not set reporter.
             */
            XMLValidationProblem prob = new XMLValidationProblem
                (loc, msg, XMLValidationProblem.SEVERITY_WARNING, probType);
            rep.report(msg, probType, prob, loc);
        }
    }
1224451
public void xml(String xml) {
    if (LogLevel.DEBUG < logConfiguration.logLevel) {
      return;
    }
    printlnInternal(LogLevel.DEBUG, logConfiguration.xmlFormatter.format(xml));
  }
978805
public void validate(String path, Schema schema, Object value, List<ValidationResult> results) {
		if (_rules == null || _rules.length == 0)
			return;

		List<ValidationResult> localResults = new ArrayList<ValidationResult>();

		for (IValidationRule rule : _rules) {
			int resultsCount = localResults.size();
			rule.validate(path, schema, value, localResults);
			if (resultsCount == localResults.size())
				return;
		}

		results.addAll(localResults);
	}
1342192
public static void validateXml(Node doc, File schemaFile)
 throws AlipayApiException {
        validateXml(doc, getInputStream(schemaFile));
    }
84417
public static void xmlWrongMethod(Class<?> aClass){
		throw new WrongMethodException (MSG.INSTANCE.message(wrongMethodException1,aClass.getSimpleName()));
	}
169569
public boolean executeSchematronDriver(InputSource inputDoc,
            File schemaFile, String phase) {

        boolean isValid = false;
        ValidationDriver driver = createSchematronDriver(phase);
        assert null != driver : "Unable to create Schematron ValidationDriver";
        InputSource is = null;
        // Fortify Mod: move fis out so it can be closed on exit
        FileInputStream fis = null;
        try {
            // FileInputStream fis = new FileInputStream(schemaFile);
            fis = new FileInputStream(schemaFile);
            is = new InputSource(fis);
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            if (driver.loadSchema(is)) {
                isValid = driver.validate(inputDoc);
                fis.close(); // Fortify addition
            } else {
                assert false : ("Failed to load Schematron schema: "
                        + schemaFile + "\nIs the schema valid? Is the phase defined?");
            }
        } catch (SAXException e) {
            assert false : e.toString();
        } catch (IOException e) {
            assert false : e.toString();
        }
        return isValid;
    }
300838
public XMLResource xml(JSONPathQuery path) throws Exception {
		Object jsonValue = path.eval(this);
		return xml(jsonValue.toString());
	}
1068539
public void checkXmlFile(File file) throws IOException, SAXException {
        validator.reset();
        InputSource is = new InputSource(new FileInputStream(file));
        is.setSystemId(file.toURI().toURL().toString());
        checkAsXML(is);
    }
725507
protected void validateXMLSchema(Message receivedMessage, XmlMessageValidationContext validationContext) {
        if (receivedMessage.getPayload() == null || !StringUtils.hasText(receivedMessage.getPayload(String.class))) {
            return;
        }

        try {
            Document doc = XMLUtils.parseMessagePayload(receivedMessage.getPayload(String.class));

            if (!StringUtils.hasText(doc.getFirstChild().getNamespaceURI())) {
                return;
            }

            log.debug("Starting XML schema validation ...");

            XmlValidator validator = null;
            XsdSchemaRepository schemaRepository = null;
            if (validationContext.getSchema() != null) {
                validator = applicationContext.getBean(validationContext.getSchema(), XsdSchema.class).createValidator();
            } else if (validationContext.getSchemaRepository() != null) {
                schemaRepository = applicationContext.getBean(validationContext.getSchemaRepository(), XsdSchemaRepository.class);
            } else if (schemaRepositories.size() == 1) {
                schemaRepository = schemaRepositories.get(0);
            } else if (schemaRepositories.size() > 0) {
                for (XsdSchemaRepository repository : schemaRepositories) {
                    if (repository.canValidate(doc)) {
                        schemaRepository = repository;
                    }
                }
                
                if (schemaRepository == null) {
                    throw new CitrusRuntimeException(String.format("Failed to find proper schema repository in Spring bean context for validating element '%s(%s)'",
                            doc.getFirstChild().getLocalName(), doc.getFirstChild().getNamespaceURI()));
                }
            } else {
                log.warn("Neither schema instance nor schema repository defined - skipping XML schema validation");
                return;
            }
            
            if (schemaRepository != null) {
                if (!schemaRepository.canValidate(doc)) {
                    throw new CitrusRuntimeException(String.format("Unable to find proper XML schema definition for element '%s(%s)' in schema repository '%s'",
                            doc.getFirstChild().getLocalName(),
                            doc.getFirstChild().getNamespaceURI(),
                            schemaRepository.getName()));
                }

                List<Resource> schemas = new ArrayList<>();
                for (XsdSchema xsdSchema : schemaRepository.getSchemas()) {
                    if (xsdSchema instanceof XsdSchemaCollection) {
                        for (Resource resource : ((XsdSchemaCollection) xsdSchema).getSchemaResources()) {
                            schemas.add(resource);
                        }                            
                    } else if (xsdSchema instanceof WsdlXsdSchema) {
                        for (Resource resource : ((WsdlXsdSchema) xsdSchema).getSchemaResources()) {
                            schemas.add(resource);
                        }
                    } else {
                        synchronized (transformerFactory) {
                            ByteArrayOutputStream bos = new ByteArrayOutputStream();
                            try {
                                transformerFactory.newTransformer().transform(xsdSchema.getSource(), new StreamResult(bos));
                            } catch (TransformerException e) {
                                throw new CitrusRuntimeException("Failed to read schema " + xsdSchema.getTargetNamespace(), e);
                            }
                            schemas.add(new ByteArrayResource(bos.toByteArray()));
                        }
                    }
                }
                
                validator = XmlValidatorFactory.createValidator(schemas.toArray(new Resource[schemas.size()]), WsdlXsdSchema.W3C_XML_SCHEMA_NS_URI);
            }
            
            SAXParseException[] results = validator.validate(new DOMSource(doc));
            if (results.length == 0) {
                log.info("XML schema validation successful: All values OK");
            } else {
                log.error("XML schema validation failed for message:\n" +
                        XMLUtils.prettyPrint(receivedMessage.getPayload(String.class)));
                
                // Report all parsing errors
                log.debug("Found " + results.length + " schema validation errors");
                StringBuilder errors = new StringBuilder();
                for (SAXParseException e : results) {
                    errors.append(e.toString());
                    errors.append("\n");
                }
                log.debug(errors.toString());

                throw new ValidationException("XML schema validation failed:", results[0]);
            }
        } catch (IOException e) {
            throw new CitrusRuntimeException(e);
        }
    }
824083
public static void xmlAttributeExistent(String path, Attribute attribute, Class<?> aClass){
		throw new XmlMappingAttributeExistException (MSG.INSTANCE.message(xmlMappingAttributeExistException2,attribute.getName(),aClass.getSimpleName(),path));
	}
711268
public boolean isValid(File file, CycloneDxSchema.Version schemaVersion) {
        return validate(file, schemaVersion).isEmpty();
    }
1157811
def schemaValidateFile(self, filename, options):
        
        ret = libxml2mod.xmlSchemaValidateFile(self._o, filename, options)
        return ret