Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7433665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:42:31+00:00 2026-05-29T09:42:31+00:00

When I try to validate XML file with a XSD schema containing regular expression,

  • 0

When I try to validate XML file with a XSD schema containing regular
expression, the function DOMDocument::schemaValidate return a validation error.

  • The value ‘RU’ is not accepted by the pattern ‘^[A-Za-z]{2}$’.
  • The value ‘6258’ is not accepted by the pattern ‘^[0-9]{4}$’.
  • The value ‘G9N3T5’ is not accepted by the pattern ‘^[A-Za-z]\d[A-Za-z]\d[A-Za-z]\d$’.

But when I compare the value and the regular expression, it should be fine.

here is a part of my XSD :

 <xsd:complexType>
    <xsd:sequence>
       <xsd:element name="RL0201Ex" type="CODE_POSTAL" minOccurs="0" maxOccurs="1">
          <xsd:annotation>
             <xsd:documentation>
                Code postal de l'adresse postale
             </xsd:documentation>
          </xsd:annotation>
       </xsd:element>
    </xsd:sequence>
 </xsd:complexType>



<xs:simpleType name="CODE_POSTAL">
   <xs:restriction base="xs:string">
      <xs:pattern value="^[A-Za-z]\d[A-Za-z]\d[A-Za-z]\d$" />
   </xs:restriction>
</xs:simpleType>

And my PHP code :

function libxml_display_error($error) {

    $return = "<br/>\n";
    $return .= "<b>Erreur ligne $error->line</b> : ";
    $return .= trim($error->message);
    $return .= "\n";

    return $return;
}

function libxml_display_errors($display_errors = true) {
    $errors = libxml_get_errors();
    $chain_errors = "";

    foreach ($errors as $error) {
        if ($error->code == "1839") {
            $chain_errors .= preg_replace('/( in\ \/(.*))/', '',     strip_tags(libxml_display_error($error)))."\n";
            if ($display_errors) {
                    echo(libxml_display_error($error));
            }
        }
    }
    libxml_clear_errors();

    return $chain_errors;
}

libxml_use_internal_errors(true);

$file   = "informations.xml";
$schema = "informations.xsd";

$dom = new DOMDocument("1.0");
$dom->load($file);

$validate = $dom->schemaValidate($schema);
if ($validate) {
   echo "<b>DOMDocument::schemaValidate() Valid schema !</b>";
} 
else {
   echo "<b>DOMDocument::schemaValidate() Generated Errors !</b><br /><br />";
   libxml_display_errors();
}

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:42:32+00:00Added an answer on May 29, 2026 at 9:42 am

    In the XSD regular expression dialect, ‘$’ is an ordinary character than matches a ‘$’ sign, not the end of the string. You don’t need anything to match the end of the string – the regex is implicitly anchored at both ends of the string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to validate an XML file against an XSD schema. The XML files
I need to validate a XML file against a schema. The XML file is
I have this code to validate an XML file against an XSD file: $file
I'm trying to validate my XML files from given XSD file with the following
I am using XmlReader to validate a XML file as per the supplied schema.
I use the following code to validate an XML file against an XSD file.
Every time I try to validate the below xsd file using XMLSpy 2012, I
Try loading this normal .jpg file in Internet Explorer 6.0. I get an error
I am using the following code to validate an an XML file against a
Someone else has already asked a somewhat similar question: Validate an Xml file against

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.