September 2004
Intermediate to advanced
712 pages
24h 45m
English
To show how new simple types can be defined, let’s extend
the phone element from the
example application to support a new attribute called location. This attribute will be used to
differentiate between work and home phone numbers. This attribute
will have a new simple type called locationType, which will be referenced
from the contactsType
definition:
<xs:complexType name="contactsType">
<xs:sequence>
<xs:element name="phone" minOccurs="0">
<xs:complexType>
<xs:attribute name="number" type="xs:string"/>
<xs:attribute name="location" type="addr:locationType"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="locationType">
<xs:restriction base="xs:string"/>
</xs:simpleType>Of course, a location type that just maps to the built-in
xs:string type isn’t particularly
useful. Fortunately, schemas can strictly control the possible
values of simple types through a mechanism called
facets.
Read now
Unlock full access