Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xml validation code is wrong #85

Open
staabm opened this issue Mar 14, 2016 · 0 comments
Open

xml validation code is wrong #85

staabm opened this issue Mar 14, 2016 · 0 comments

Comments

@staabm
Copy link
Member

staabm commented Mar 14, 2016

the code sample - provided by me in fa985ed - doesnt work :/.

I tried a lot of different ways but wasnt able to find one which works using the xml-extension.
As a workaround I localy work with a DOMDocument based approach:

    static private function validateXml($xmlString, $schema) {

        $libxml_display_error = function ($error)
        {
            $return = "";
            switch ($error->level) {
                case LIBXML_ERR_WARNING:
                    $return .= "Warning $error->code: ";
                    break;
                case LIBXML_ERR_ERROR:
                    $return .= "Error $error->code: ";
                    break;
                case LIBXML_ERR_FATAL:
                    $return .= "Fatal Error $error->code: ";
                    break;
            }
            $return .= trim($error->message);
            if ($error->file) {
                $return .=    " in $error->file";
            }
            $return .= " on line $error->line";

            return $return;
        };

        libxml_use_internal_errors(TRUE);

        $xml = new \DOMDocument();
        $xml->loadXml($xmlString);

        if (!$xml->schemaValidate($schema)) {
            echo '> DOMDocument::schemaValidate() Generated Errors!'."\n";
            echo 'Schema:'. $schema;

            var_dump($xmlString);

            $errors = libxml_get_errors();
            foreach ($errors as $error) {
                debug($libxml_display_error($error));
            }
            exit();
        }
    }

just to let you know...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant