문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top