public static function validateXML($xml, $schema, $debug = false)
    {
        assert('is_string($xml) || $xml instanceof DOMDocument');
        assert('is_string($schema)');

        libxml_clear_errors();
        libxml_use_internal_errors(true);

        if ($xml instanceof DOMDocument) {
            $dom = $xml;
        } else {
            $dom = new DOMDocument;
            $dom = self::loadXML($dom, $xml);
            if (!$dom) {
                return 'unloaded_xml';
            }
        }

        $schemaFile = __DIR__.'/schemas/' . $schema;
        $oldEntityLoader = libxml_disable_entity_loader(false);
        $res = $dom->schemaValidate($schemaFile);
        libxml_disable_entity_loader($oldEntityLoader);
        if (!$res) {
            $xmlErrors = libxml_get_errors();
            syslog(LOG_INFO, 'Error validating the metadata: '.var_export($xmlErrors, true));

            if ($debug) {
                foreach ($xmlErrors as $error) {
                    echo htmlentities($error->message."\n");
                }
            }

            return 'invalid_xml';
        }


        return $dom;
    }
public static function validateXML($xml, $schema, $debug = false)
    {
        assert('is_string($xml) || $xml instanceof DOMDocument');
        assert('is_string($schema)');

        libxml_clear_errors();
        libxml_use_internal_errors(true);

        if ($xml instanceof DOMDocument) {
            $dom = $xml;
        } else {
            $dom = new DOMDocument;
            $dom = self::loadXML($dom, $xml);
            if (!$dom) {
                return 'unloaded_xml';
            }
        }

        $schemaFile = __DIR__.'/schemas/' . $schema;
        $oldEntityLoader = libxml_disable_entity_loader(false);
        $res = $dom->schemaValidate($schemaFile);
        libxml_disable_entity_loader($oldEntityLoader);
        if (!$res) {
            $xmlErrors = libxml_get_errors();
            syslog(LOG_INFO, 'Error validating the metadata: '.var_export($xmlErrors, true));

            if ($debug) {
                foreach ($xmlErrors as $error) {
                    echo htmlentities($error->message."\n");
                }
            }

            return 'invalid_xml';
        }


        return $dom;
    }
public static function validateXML ( $ xml , $ schema , $ debug = false ) { assert ( 'is_string($xml) || $xml instanceof DOMDocument' ) ; assert ( 'is_string($schema)' ) ; libxml_clear_errors ( ) ; libxml_use_internal_errors ( true ) ; if ( $ xml instanceof DOMDocument ) { $ dom = $ xml ; } else { $ dom = new DOMDocument ; $ dom = self :: loadXML ( $ dom , $ xml ) ; if ( ! $ dom ) { return 'unloaded_xml' ; } } $ schemaFile = __DIR__ . '/schemas/' . $ schema ; $ oldEntityLoader = libxml_disable_entity_loader ( false ) ; $ res = $ dom -> schemaValidate ( $ schemaFile ) ; libxml_disable_entity_loader ( $ oldEntityLoader ) ; if ( ! $ res ) { $ xmlErrors = libxml_get_errors ( ) ; syslog ( LOG_INFO , 'Error validating the metadata: ' . var_export ( $ xmlErrors , true ) ) ; if ( $ debug ) { foreach ( $ xmlErrors as $ error ) { echo htmlentities ( $ error -> message . "\n" ) ; } } return 'invalid_xml' ; } return $ dom ; }
This function attempts to validate an XML string against the specified schema.

It will parse the string into a DOM document and validate this document against the schema.

@param string|DOMDocument $xml The XML string or document which should be validated.
@param string $schema The schema filename which should be used.
@param bool $debug To disable/enable the debug mode

@return string|DOMDocument $dom  string that explains the problem or the DOMDocument

@throws Exception
This function attempts to validate an XML string against the specified schema .