Articles → XSD → Restrictions in XSD

Restrictions in XSD




















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










<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>





Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, January 07, 2015

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250