Fixed Values

Contact Us or call 1-877-932-8228
Fixed Values

Fixed Values

Element values can be fixed, meaning that, if they appear in the instance document, they must contain a specified value. Fixed elements are often used for boolean switches.

Code Sample:

<?xml version="1.0"?>
<xs:schema xmlns:xs="">
	<xs:simpleType name="Salary">
		<xs:restriction base="xs:decimal">
			<xs:minInclusive value="10000"/>
			<xs:maxInclusive value="90000"/>
			<xs:fractionDigits value="2"/>
			<xs:totalDigits value="7"/>
	<xs:simpleType name="JobTitle">
		<xs:restriction base="xs:string">
			<xs:enumeration value="Sales Manager"/>
			<xs:enumeration value="Salesperson"/>
			<xs:enumeration value="Receptionist"/>
			<xs:enumeration value="Developer"/>
	<xs:element name="Employee">
				<xs:element name="Salary" type="Salary"/>
				<xs:element name="Title" type="JobTitle"/>
				<xs:element name="Status" type="xs:string" fixed="current" 

The MinOccurs attribute is used to make the Status element optional. However, if it is used, it must contain the value current or be left empty, in which case, the value current is implied. The file SimpleTypes/Demos/LauraSmith.xml in the Demos folder validates against this schema.