Restrictions In XSD
- Restrictions on Values
- Restriction on set of values
- Restriction on series of values
- Restrictions on whitespace characters
- Restrictions on length
Restrictions On Values
<element name=“name_of_element">
<simpleType>
<restriction base=“integer">
<minInclusive value = “min_val" />
</restriction>
</simpleType>
</element>
<element name=“name_of_element">
<simpleType>
<restriction base=“integer">
<maxInclusive value = “max_val" />
</restriction>
</simpleType>
</element>
<person>
<name>Karan</name>
<age>33</age>
<maritalStatus>Single</maritalStatus>
</person>
<schema
xmlns="http://www.w3.org/2001/XMLSchema">
<element name="person">
<complexType>
<sequence>
<element name="name" type="string"/>
<element name="age">
<simpleType>
<restriction base="integer">
<minInclusive value = "18" />
<maxInclusive value = "33" />
</restriction>
</simpleType>
</element>
<element name="maritalStatus" type="string" />
</sequence>
</complexType>
</element>
</schema>
Restriction On Set Of Values
<element name=“element_value">
<simpleType>
<restriction base=“string">
<enumeration value=“Val 1"/>
<enumeration value=" Val 2"/>
<enumeration value=“Val 3"/>
</restriction>
</simpleType>
</element>
<person>
<name>Karan</name>
<age>33</age>
<maritalStatus>Single</maritalStatus>
</person>
<schema
xmlns="http://www.w3.org/2001/XMLSchema">
<element name="person">
<complexType>
<sequence>
<element name="name" type="string"/>
<element name="age" type="integer"/>
<element name="maritalStatus">
<simpleType>
<restriction base="string">
<enumeration value="Married"/>
<enumeration value="Single"/>
<enumeration value="Divorced"/>
</restriction>
</simpleType>
</element>
</sequence>
</complexType>
</element>
</schema>
Restriction On Series Of Values
<element name=“element_value">
<simpleType>
<restriction base=“string">
<pattern value=“pattern”/>
</restriction>
</simpleType>
</element>
<student>
<name>Karan</name>
<Section>E</Section>
</student>
<schema
xmlns="http://www.w3.org/2001/XMLSchema">
<element name="student">
<complexType>
<sequence>
<element name="name" type="string"/>
<element name="Section">
<simpleType>
<restriction base="string">
<pattern value = "[A-E]" />
</restriction>
</simpleType>
</element>
</sequence>
</complexType>
</element>
</schema>
Restrictions On Whitespace Characters
- preserve – preserve option ensures that XML processor will not remove any white space.
- collapse – collapse option ensures that XML processor removes white spaces
<element name=“element_value">
<simpleType>
<restriction base=“string">
<whiteSpace value=“preserve”/>
</restriction>
</simpleType>
</element>
<element name=“element_value">
<simpleType>
<restriction base=“string">
<whiteSpace value=“collapse”/>
</restriction>
</simpleType>
</element>
<person>
<name>Karan</name>
<Section> E </Section>
</person>
Restrictions On Length
<element name=“element_value">
<simpleType>
<restriction base=“string">
<length value=“max_length”/>
</restriction>
</simpleType>
</element>
<student>
<name>Karan</name>
<Section>E</Section>
</student>
<schema
xmlns="http://www.w3.org/2001/XMLSchema">
<element name="student">
<complexType>
<sequence>
<element name="name" type="string"/>
<element name="Section">
<simpleType>
<restriction base="string">
<length value="1" />
</restriction>
</simpleType>
</element>
</sequence>
</complexType>
</element>
</schema>