Specifying Element Type Locally

Contact Us or call 1-877-932-8228
Specifying Element Type Locally

Specifying Element Type Locally

So far in this lesson, we have been defining simple types globally and then setting the type attribute of element declarations to be of our derived simple types. This makes it easy to reuse a simple type across multiple elements, as we saw with the ProperName type in the last exercise.

It is also possible to define the type of an element locally. The type is then unnamed and applicable only to that element. The only reason to do this is to clearly show that the type is specific to that element and not meant for reuse.

Code Sample:

SimpleTypes/Demos/PasswordLocal.xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
	<xs:element name="User">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="PW">
					<xs:simpleType>
						<xs:restriction base="xs:string">
							<xs:length value="8"/>
							<xs:whiteSpace value="collapse"/>
						</xs:restriction>
					</xs:simpleType>
				</xs:element>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
</xs:schema>
Next