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