Declaring a Global Simple Type
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" ...> <xsd:simpleType name="type-name"> ... </xsd:simpleType> </schema>
A simpleType declared as a direct child of the schema root element is considered a 'global' simpleType.
A 'name' attribute is required for a global defined simpleType.
Referencing a Global Simple Type
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" ...> <xsd:attribute name="attribute-name" type="type-name" use="optional" default="string-value"/> <xsd:element name="element-name" type="type-name"/> <xsd:simpleType name="type-name"> ... </xsd:simpleType> </schema>
Reuse a global defined simpleType, by referencing the simpleType, using the 'type' attribute available for element and attribute.
Declaring a Local Simple Type
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" ...> <xsd:attribute name="attribute-name" use="optional" default="string-value"> <xsd:simpleType> ... </xsd:simpleType> <attribute> <xsd:element name="element-name"> <xsd:simpleType> ... </xsd:simpleType> </xsd:element> </schema>
A simpleType declared as a child of the element or attribute element is considered a 'local' simpleType.
The type attribute cannot be used together with a simpleType child element.
A local simple type does not have a name.
Derivation by restriction.
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" ...> <xsd:simpleType name="type-name"> <xsd:restriction base="xsd:string"> <xs:maxLength value="12"/> ... </xsd:restriction> </xsd:simpleType> <xsd:simpleType name="another-type-name"> <xsd:restriction base="type-name"> <xs:minLength value="4"/> ... </xsd:restriction> </xsd:simpleType> </schema>
Define the to be restricted type using the 'base' attribute or with an anonymous inner class.
Both user-defined and built-in types can be 'restricted'.
Use any of the facets to define restrictions.
enumerations
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" ...> <xsd:simpleType name="type-name"> <xsd:restriction base="xsd:string"> <xs:enumeration value="one"/> ... <xs:enumeration value="ten"/> </xsd:restriction> </xsd:simpleType> </schema>
Use enumeration facets to create a type that only allows values defined by the enumeration facets.
lists
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" ...> <xsd:simpleType name="type-name"> <xsd:list itemType="xsd:string"/> </xsd:simpleType> <xsd:simpleType name="type-name"> <xsd:list> <xsd:simpleType> ... </xsd:simpleType> </xsd:list> </xsd:simpleType> </schema>
Specifies a list values separated by spaces.
The type of the list can be specified using the itemType attribute or with an anonymous inner class.