I had xsd as follows
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="College">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="Name" maxOccurs="unbounded" minOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
It must allow only 2 values Example Only ABC and CBS are allowed
<college>
<Name>ABC</Name>
<Name>ABC</Name>
<Name>CBS</Name>
</college>
which should not allowed
<college>
<Name>ABC</Name>
<Name>ABC</Name>
<Name>CBS</Name>
<Name>XYZ</Name>
</college>
Since you have a countable number of options you can use an enumeration to restrict them. Replace your xs:element
declaration with this:
<xs:element name="Name" maxOccurs="unbounded" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="ABC"/>
<xs:enumeration value="CBS"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Try pattern matching
<xsd:element name="elementName">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="/^[ABC|CBS]$/"></xsd:pattern>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.