Domanda

I want to create a restriction on the studentId. All Id start with 2 capital letters, followed by 6 digits.

This is my XML:

 <resource studentId="BB244663" type="course">
        <course>Advanced Mechanics</course>
        <courseNumber>764839211-19-H</courseNumber>
 </resource>   

And this is the schema rule that I made

<xs:element name="resource">
<xs:complexType>
  <xs:sequence>
    <xs:element name="course" type="xs:string"/>
    <xs:element name="courseNumber" type="xs:string"/>
  </xs:sequence>
  <xs:attribute name="studentId"> <!-- rule starts here ###-->
      <xs:simpleType>
            <xs:restriction base="xs:string">
                <xs:pattern value="[A-Z] [A-Z] [0-9] [0-9] [0-9] [0-9] [0-9] [0-9]"/>
            </xs:restriction>
      </xs:simpleType>
  </xs:attribute>  <!-- rule ends here ###-->
  <xs:attribute name="type" type="xs:string" use="required"/>
</xs:complexType>

Every time I try and validate the XML file I get thrown this error:

cvc-pattern-valid: Value 'BB244663' is not facet-valid with respect to pattern '[A-Z] [A-Z] [0-9] [0-9] [0-9] [0-9] [0-9] [0-9]' for type '#AnonType_studentIdresource'. [13] 
cvc-attribute.3: The value 'BB244663' of attribute 'studentId' on element 'resource' is not valid with respect to its type, 'null'. [13] 

I looked online but I can't see what's wrong with the restriction, except that maybe it's because it's an attribute not an element?

È stato utile?

Soluzione

Your pattern is not entirely correct. The spaces inside are actually used as pattern.

Changing your pattern value to

[A-Z]{2}[0-9]{6}

should solve the problem.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top