0

I created the following XML document along with XSD but i don't know why the xml validator told me that the name, email, and telephone elements are not facet-valid with respect to the pattern

here is the XML and XSD..

 <?xml version="1.0" encoding="UTF-8"?>
<cv xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:noNamespaceSchemaLocation="CV.xsd">
    <me>
        <name>Maxieem Holand Telmaison</name>
        <address>
            <address_line1>Street 920</address_line1>
            <address_line2>area 35</address_line2>
            <city>Doha</city>
            <country>Qatar</country>
        </address>
        <telephone>(974)33927090</telephone>
        <email>maxholand76@gmail.com</email>
    </me>
    </cv>

the XSD File where i added the pattern

  <?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
   
<xs:element name="cv" type="Cv_type"/>   
<!-- CV Main Body contents-->
<xs:complexType name="Cv_type"> 
   <xs:sequence>
 <xs:element name="me" type="me_type"/>
   </xs:sequence>
</xs:complexType>    
<!-- -\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- -->
<!-- Me Type defination    -->
<xs:complexType name="me_type">
    <xs:sequence>
        <xs:element name="name" type="name_type"/>
        <xs:element name="address" type="address_type"/>
        <xs:element name="telephone" type="telepone_type"/>
        <xs:element name="email" type="email_type"/>
    </xs:sequence>
</xs:complexType>
     
<xs:simpleType name="name_type">
        <xs:restriction base="xs:string">
            <xs:pattern value="^([a-zA-Z]{2,}\s[a-zA-Z]{1,}'?-?[a-zA-Z]{2,}\s?([a-zA-Z]{1,})?)$"/>
        </xs:restriction>   
</xs:simpleType>
    
 <xs:complexType name="address_type">
     <xs:sequence>
         <xs:element name="address_line1" type="xs:string"/>
         <xs:element name="address_line2" type="xs:string"/>
         <xs:element name="city" type="xs:string"/>
         <xs:element name="country" type="xs:string"/>
     </xs:sequence>
 </xs:complexType>
  
 <xs:simpleType name="telepone_type">
    <xs:restriction base="xs:string">
      <xs:pattern value="^(\+\d{1,2}\s?)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{1,6}\s*$"/>
    </xs:restriction>
 </xs:simpleType>
    
 <xs:simpleType name="email_type">
   <xs:restriction base="xs:string">
     <xs:pattern value="^\w+@[a-zA-Z_]+\.[a-zA-Z]{2,3}$"/>
   </xs:restriction>
</xs:simpleType>
    <!-- -\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- -->

 </xs:schema>

Q: can anyone tell me what is wrong with the pattern expressions?

MaxPody
  • 1
  • 3

1 Answers1

0

XSD patterns should not use ^ and $ - the pattern is implicitly anchored, and (unfortunately) ^ and $ are not metacharacters in the XSD regex dialect, they are ordinary characters that represent themselves.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • thank you so much. as I went through multiple sites to figure it out but no one gives me the answer except you .. appreciated – MaxPody Mar 17 '21 at 04:57