protected function schemaValidate(\DOMDocument $dom, \SplFileInfo $xsdFile)
    {
        $errorMessages = [];

        try {
            libxml_use_internal_errors(true);

            if (!$dom->schemaValidate($xsdFile->getRealPath())) {
                $errors = libxml_get_errors();

                foreach ($errors as $error) {
                    $errorMessages[] = sprintf(
                        'XML error "%s" [%d] (Code %d) in %s on line %d column %d' . "\n",
                        $error->message,
                        $error->level,
                        $error->code,
                        $error->file,
                        $error->line,
                        $error->column
                    );
                }

                libxml_clear_errors();
            }

            libxml_use_internal_errors(false);
        } catch (\Exception $ex) {
            libxml_use_internal_errors(false);
        }

        return $errorMessages;
    }
protected function schemaValidate(\DOMDocument $dom, \SplFileInfo $xsdFile)
    {
        $errorMessages = [];

        try {
            libxml_use_internal_errors(true);

            if (!$dom->schemaValidate($xsdFile->getRealPath())) {
                $errors = libxml_get_errors();

                foreach ($errors as $error) {
                    $errorMessages[] = sprintf(
                        'XML error "%s" [%d] (Code %d) in %s on line %d column %d' . "\n",
                        $error->message,
                        $error->level,
                        $error->code,
                        $error->file,
                        $error->line,
                        $error->column
                    );
                }

                libxml_clear_errors();
            }

            libxml_use_internal_errors(false);
        } catch (\Exception $ex) {
            libxml_use_internal_errors(false);
        }

        return $errorMessages;
    }
protected function schemaValidate ( \ DOMDocument $ dom , \ SplFileInfo $ xsdFile ) { $ errorMessages = [ ] ; try { libxml_use_internal_errors ( true ) ; if ( ! $ dom -> schemaValidate ( $ xsdFile -> getRealPath ( ) ) ) { $ errors = libxml_get_errors ( ) ; foreach ( $ errors as $ error ) { $ errorMessages [ ] = sprintf ( 'XML error "%s" [%d] (Code %d) in %s on line %d column %d' . "\n" , $ error -> message , $ error -> level , $ error -> code , $ error -> file , $ error -> line , $ error -> column ) ; } libxml_clear_errors ( ) ; } libxml_use_internal_errors ( false ) ; } catch ( \ Exception $ ex ) { libxml_use_internal_errors ( false ) ; } return $ errorMessages ; }
Validate the schema of a XML file with a given xsd file

@param \DOMDocument $dom The XML document
@param \SplFileInfo $xsdFile The XSD file
@return array an array of errors if validation fails, otherwise an empty array
Validate the schema of a XML file with a given xsd file