Jump to content
Sign in to follow this  

xml validation with schema failed but the xml is valid

Recommended Posts


<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <xsd:simpleType name="MgmtCodetyp">
        <xsd:restriction base="xsd:string">
             <xsd:pattern value="[A-Z][A-Z]([A-Z]|[0-9])"></xsd:pattern>

    <xsd:element name="MgmtCode" type="MgmtCodetyp"></xsd:element>





PHP Code


        $file = "data.xml";

        function libxml_display_error($error) {

                $return = "\n";

                switch ($error->level) {
                        case LIBXML_ERR_ERROR:
                                $return .= "[ERROR] ";
                        case LIBXML_ERR_FATAL:
                                $return .= "[FATAL] ";
                                $return .= "[uNKNOWN] ";

                $return .= trim($error->message);
                $return .= " [line: $error->line]\n";

                return $return;

        function libxml_display_errors() {

                $errors = libxml_get_errors();

                foreach ($errors as $error) {
                        if ($error -> level != LIBXML_ERR_WARNING) {
                                print libxml_display_error($error);


        // Enable user error handling

        $xml = new DOMDocument;
        $xml -> load("kkk.xml");
        if (!$xml -> schemaValidate("kkk.xsd")) {

        else {
                print "no error\n";




[ERROR] Element 'MgmtCode': [facet 'pattern'] The value 'AGF' is not accepted by the pattern '[A-Z][A-Z]([A-Z]|[0-9])'. [line: 1]

[ERROR] Element 'MgmtCode': 'AGF' is not a valid value of the atomic type 'MgmtCodetyp'. [line: 1]



The XML is a perfectly valid xml. I don't understand why it failed the XSD.

Share this post

Link to post
Share on other sites

Works fine for me. That's the exact code and XML you're trying?

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.