Validate the given xmlDocument, using any schemas specified in the document itself.

@throws PluginException for any validation or IO errors.
428425
public void validate(Document doc) {
    	try {
    		doValidate(doc);
    	}
        catch (Exception e) {
            throw new PluginException("Error validating document: " + e, e);
        }
    }
109591
def validate(self, schema_str, xml_valid):
        
        # TODO: be able to get doc for error given an xsd.
        # Changed path to allow have xsd that are imported by others xsd in the
        # same library, and not call to SAT page each time that is generated
        # a new XML.
        with change_path():
            path = os.path.join(
                os.path.dirname(os.path.realpath(__file__)), 'templates')
            os.chdir(path)
            schema_root = etree.parse(StringIO(schema_str))
            schema = etree.XMLSchema(schema_root)
        try:
            tree = etree.parse(StringIO(xml_valid.encode('UTF-8')))
            schema.assertValid(tree)
        except etree.DocumentInvalid as ups:
            self.ups = ups
        finally:
            if self.ups:
                self.valid = False
            else:
                self.valid = True
            return self.valid
713213
def validateDocument(self, doc):
        
        if doc is None: doc__o = None
        else: doc__o = doc._o
        ret = libxml2mod.xmlValidateDocument(self._o, doc__o)
        return ret
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);
    }
  }
454218
public static void validateXMLSchema(InputStream xsdStream, InputStream xmlStream) throws IOException, SAXException {
        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = factory.newSchema(new StreamSource(xsdStream));
        Validator validator = schema.newValidator();
        validator.validate(new StreamSource(xmlStream));
    }
51992
protected function validateCommons(/** @noinspection PhpUnusedParameterInspection */
        &$document_data, &$data, array $data_pointer, array $parent_data_pointer, ISchema $document, $schema, ValidationResult $bag, array &$defaults = null): bool
    {
        $ok = true;

        // type
        if (property_exists($schema, 'type')) {
            if (is_string($schema->type)) {
                if (!$this->helper->typeExists($schema->type)) {
                    throw new SchemaKeywordException(
                        $schema,
                        'type',
                        $schema->type,
                        "'type' keyword contains unknown value: " . $schema->type
                    );
                }
            } elseif (is_array($schema->type)) {
                /** @noinspection PhpParamsInspection */
                if (count($schema->type) === 0) {
                    throw new SchemaKeywordException(
                        $schema,
                        'type',
                        $schema->type,
                        "'type' keyword must not be an empty array"
                    );
                }
                /** @noinspection PhpParamsInspection */
                if ($schema->type != array_unique($schema->type)) {
                    throw new SchemaKeywordException(
                        $schema,
                        'type',
                        $schema->type,
                        "'type' keyword contains duplicate items"
                    );
                }
                foreach ($schema->type as $type) {
                    if (!is_string($type)) {
                        throw new SchemaKeywordException(
                            $schema,
                            'type',
                            $type,
                            "'type' keyword must have only strings if array, found " . gettype($type)
                        );
                    }
                    if (!$this->helper->typeExists($type)) {
                        throw new SchemaKeywordException(
                            $schema,
                            'type',
                            $type,
                            "'type' keyword contains unknown value: " . $type
                        );
                    }
                }
                unset($type);
            } else {
                throw new SchemaKeywordException(
                    $schema,
                    'type',
                    $schema->type,
                    "'type' keyword must be a string or an array of strings, " . gettype($schema->type) . " given"
                );
            }

            if (!$this->helper->isValidType($data, $schema->type)) {
                $ok = false;
                $bag->addError(new ValidationError($data, $data_pointer, $parent_data_pointer, $schema, 'type', [
                    'expected' => $schema->type,
                    'used' => $this->helper->type($data, true),
                ]));
                if ($bag->isFull()) {
                    return false;
                }
            }
        }

        // const
        if (property_exists($schema, 'const')) {
            if (!$this->helper->equals($data, $schema->const, $defaults)) {
                $ok = false;
                $bag->addError(new ValidationError($data, $data_pointer, $parent_data_pointer, $schema, 'const', [
                    'expected' => $schema->const,
                ]));
                if ($bag->isFull()) {
                    return false;
                }
            }
        }

        // enum
        if (property_exists($schema, 'enum')) {
            if (!is_array($schema->enum)) {
                throw new SchemaKeywordException(
                    $schema,
                    'enum',
                    $schema->enum,
                    "'enum' keyword must be an array, " . gettype($schema->enum) . " given"
                );
            }
            if (count($schema->enum) === 0) {
                throw new SchemaKeywordException(
                    $schema,
                    'enum',
                    $schema->enum,
                    "'enum' keyword must not be empty"
                );
            }

            $found = false;
            foreach ($schema->enum as $v) {
                if ($this->helper->equals($data, $v, $defaults)) {
                    $found = true;
                    break;
                }
            }
            unset($v);
            if (!$found) {
                $ok = false;
                $bag->addError(new ValidationError($data, $data_pointer, $parent_data_pointer, $schema, 'enum', [
                    'expected' => $schema->enum,
                ]));
                if ($bag->isFull()) {
                    return false;
                }
            }
            unset($found);
        }

        return $ok;
    }
150117
def _validate(self, inst: "InstanceNode", scope: ValidationScope,
                  ctype: ContentType) -> None:
        """"""
        if scope.value & ValidationScope.syntax.value:   # schema
            self._check_schema_pattern(inst, ctype)
        for m in inst:
            inst._member(m).validate(scope, ctype)
        super()._validate(inst, scope, ctype)
98672
public boolean validateAgainstXsdFile(String xsdFileName) {
        String xsdContent = new FileFixture().textIn(xsdFileName);
        return new XMLValidator().validateAgainst(content, xsdContent);
    }
844767
def validate(self, schema):
        
        try:
            validate(instance=self.to_dict(), schema=schema, cls=Draft4Validator)
        except ValidationError as e:
            raise ValidationError(_validate_err_template.format(VDOM_SCHEMA, e))
447414
public function validateSchemaVersion($xml)
    {
        libxml_use_internal_errors(true);

        try {
            $theSchema = self::getSchemaVersion($xml);
            $doiXML = new \DOMDocument();
            $doiXML->loadXML($xml);
        } Catch (\Exception $e) {
            $this->validationMessage = $e->getMessage();
            return false;
        }

        $schemaPath = SchemaProvider::getSchema($theSchema);

        // if the schema is not stored locally, lookup on datacite
        if (!is_file($schemaPath)) {
            $schemaPath = 'http://schema.datacite.org/meta' . $theSchema;
        }

        $result = $doiXML->schemaValidate($schemaPath);

        foreach (libxml_get_errors() as $error) {
            $this->validationMessage = $error->message;
        }
        return $result;
    }
1151396
protected function loadXml( $xml )
	{
		$xsv	= new XML_DOM_SyntaxValidator;
		if( !$xsv->validate( $xml ) )
			throw new Exception( "XML Document is not valid:".$xsv->getErrors() );
		$this->document	= $xsv->getDocument();
		$this->clearOptions();
		foreach( $this->attributes as $attribute )
			if( isset( $this->document->$attribute ) )
				$this->setOption( $attribute, $this->document->$attribute );
	}
877577
private void initDocumentParser() throws ParserConfigurationException {

    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();

    docBuilderFactory.setNamespaceAware(false);
    docBuilderFactory.setValidating(true);

    docBuilderFactory.setAttribute(
        "http://java.sun.com/xml/jaxp/properties/schemaLanguage",
        "http://www.w3.org/2001/XMLSchema");

    docBuilderFactory.setAttribute(
        "http://java.sun.com/xml/jaxp/properties/schemaSource", resolveSchemaSource());

    docBuilder = docBuilderFactory.newDocumentBuilder();

    docBuilder.setErrorHandler(this);

    xpath = XPathFactory.newInstance().newXPath();
  }
649682
public function validateXML($xml)
    {
        $xmlValidator = new XMLValidator();
        $result = $xmlValidator->validateSchemaVersion($xml);
        if ($result === false) {
            $this->setResponse("verbosemessage", $xmlValidator->getValidationMessage());
            return false;
        }
        return true;
    }
376639
public static Document parse(File xmlFile, EntityResolver resolver) {

        try {
            DocumentBuilder parser = createParser(resolver);
            return parser.parse(xmlFile);
        }
        catch (Exception e) {
            throw new PluginException("Error parsing XML document '" + xmlFile + "': " + e, e);
        }
    }
866733
public function validatePlugin($plugin)
    {
        if($plugin instanceof AdapterInterface) {
            return;
        }

        throw new InvalidPluginException(sprintf(
            'Plugin of type %s is invalid; must implement %s\AdapterInterface and set ID',
            (is_object($plugin) ? get_class($plugin) : gettype($plugin)),
            __NAMESPACE__
        ));
    }
105563
public function validateSchema(\DOMDocument $dom)
    {
        $schemaLocations = ['http://symfony.com/schema/dic/services' => str_replace('\\', '/', __DIR__.'/schema/dic/services/services-1.0.xsd')];

        if ($element = $dom->documentElement->getAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'schemaLocation')) {
            $items = preg_split('/\s+/', $element);
            for ($i = 0, $nb = \count($items); $i < $nb; $i += 2) {
                if (!$this->container->hasExtension($items[$i])) {
                    continue;
                }

                if (($extension = $this->container->getExtension($items[$i])) && false !== $extension->getXsdValidationBasePath()) {
                    $ns = $extension->getNamespace();
                    $path = str_replace([$ns, str_replace('http://', 'https://', $ns)], str_replace('\\', '/', $extension->getXsdValidationBasePath()).'/', $items[$i + 1]);

                    if (!is_file($path)) {
                        throw new RuntimeException(sprintf('Extension "%s" references a non-existent XSD file "%s"', \get_class($extension), $path));
                    }

                    $schemaLocations[$items[$i]] = $path;
                }
            }
        }

        $tmpfiles = [];
        $imports = '';
        foreach ($schemaLocations as $namespace => $location) {
            $parts = explode('/', $location);
            $locationstart = 'file:///';
            if (0 === stripos($location, 'phar://')) {
                $tmpfile = tempnam(sys_get_temp_dir(), 'symfony');
                if ($tmpfile) {
                    copy($location, $tmpfile);
                    $tmpfiles[] = $tmpfile;
                    $parts = explode('/', str_replace('\\', '/', $tmpfile));
                } else {
                    array_shift($parts);
                    $locationstart = 'phar:///';
                }
            }
            $drive = '\\' === \DIRECTORY_SEPARATOR ? array_shift($parts).'/' : '';
            $location = $locationstart.$drive.implode('/', array_map('rawurlencode', $parts));

            $imports .= sprintf('  <xsd:import namespace="%s" schemaLocation="%s" />'."\n", $namespace, $location);
        }

        $source = <<<EOF
<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema xmlns="http://symfony.com/schema"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://symfony.com/schema"
    elementFormDefault="qualified">

    <xsd:import namespace="http://www.w3.org/XML/1998/namespace"/>
$imports
</xsd:schema>
EOF
        ;

        $disableEntities = libxml_disable_entity_loader(false);
        $valid = @$dom->schemaValidateSource($source);
        libxml_disable_entity_loader($disableEntities);

        foreach ($tmpfiles as $tmpfile) {
            @unlink($tmpfile);
        }

        return $valid;
    }
1259432
public static void validateWebXML () throws Exception
  {
    final IMicroDocument aDoc = MicroReader.readMicroXML (new File ("src/main/webapp/WEB-INF/web.xml"));
    if (aDoc != null)
      for (final IMicroNode aNode : new MicroRecursiveIterator (aDoc.getDocumentElement ()))
        if (aNode.isElement ())
        {
          final IMicroElement e = (IMicroElement) aNode;
          if (e.getTagName ().endsWith ("-class"))
          {
            final String sClassName = e.getTextContentTrimmed ();
            try
            {
              Class.forName (sClassName);
            }
            catch (final Exception ex)
            {
              LOGGER.error ("Failed to resolve class '" + sClassName + "'");
              throw ex;
            }
          }
        }
  }