10.5. The simpleType Element

The XML representation of a simple type is a simpleType element. A simpleType must contain exactly one of the following elements: restriction, list, or union. Because all three of the aforementioned elements are moderately complex, this chapter includes a section for each element. The simpleType and restriction elements cover the majority of simple types, which are frequently easy derivations of built-in datatypes.

10.5.1. Attributes of a simpleType Element

The simpleType element has only three attributes: final, id, and name. All three of these attributes behave similarly to the identically named attributes for the element element. Chapter 8 provides details on the element element. Table 10.1 provides an overview of the simple type attributes.

Table 10.1. Attribute Summary of a simpleType Element
Attribute Description
final The value of the final attribute is a space-delimited list containing any combination of ‘list’, ‘union’, or ‘restriction’. This further restricts derivations of simple types specifically list, union, or restriction, respectively. The value ‘#all’ indicates that no further derivations are possible.
id The value of the id attribute uniquely identifies an element.
name The value of the name attribute is the name of a simple type. A derived simple type references this name as the base simple type. An element type references this name to associate a structure type.

10.5.1.1. The final Attribute of a simpleType Element

The final attribute restricts the ability to derive other types. Its values are defined as follows:

  • list: prevents a derived type from creating a list of the restricted type.

  • union: prevents a derived type from using the restricted type in a union.

  • restriction: prevents a derived type from using constraining facets to further restrict the restricted type.

  • #all: prohibits all further derivations.

Attribute Overview

simpleType: final

Value: Any or all of ‘list’, ‘union’, or ‘restriction’. The value ‘#all’ can be used as a shortcut for a list containing all three values.
Default: In general, there is no default. However, a schema element can set a global default by setting the finalDefault attribute.
Constraints: None.
Required: No.


The partNumberType in Listing 10.2 has the final attribute set to union. Another simple type cannot be a union that contains partNumberType as a member type. Similarly, the assemblyPartNumberType in Listing 10.2 cannot have any derived classes, including those that might further restrict the value of an element in a corresponding XML instance. Listings 10.1, 10.3, 10.6, 10.8, and 10.9 also contain examples that incorporate the final attribute.

Warning

Many existing XML parsers do not respect the final attribute of simple types or complex types.


10.5.1.2. The id Attribute of a simpleType Element

The value of an id attribute uniquely identifies an element within the set of schema documents that comprise an XML schema. Listing 10.1 provides an example that associates an id attribute with a simpleType element.

Attribute Overview

simpleType: id

Value: An ID.
Default: None.
Constraints: An id must be unique within an XML schema.
Required: No.


Most of the examples in this chapter uniquely identify the type.

Warning

Many of the existing XML parsers to not enforce the uniqueness of an id.


10.5.1.3. The name Attribute of a simpleType Element

The value of name is the name used in the schema to reference a simpleType.

Attribute Overview

simpleType: name

Value: An NCName.
Default: None.
Constraints: None.
Required: Yes, unless the simpleType is local to an element type, another simple type, or a complex type—in which case the name is prohibited. A simpleType without a name is anonymous.


Section 10.4.3 discusses the usage and requirements of the name attribute. Listing 10.1 provides an example that associates the name attribute with a simpleType element.

10.5.2. Content Options for a simpleType Element

This section itemizes the possible child elements of a simpleType element. Table 10.2 provides a quick summary of all the content options.

Table 10.2. Content Options for a simpleType Element
Element Description
annotation The annotation element, discussed in Section 7.5, provides a way to document schema elements.
restriction The restriction element provides functionality for adding constraining facets to a derived simple type.
list The list element provides functionality for creating a simple type that specifies a list of simple type values.
union The union element provides functionality for creating a simple type that specifies a selection from a set of simple type values.

The content pattern for a simpleType element is:

annotation? (restriction | list | union) 

10.5.3. Constraining Facets of a simpleType Element

Constraining facets can be associated with a simple type for three reasons:

  • The user-derived simple type further restricts a built-in datatype or another, atomic user-derived simple type ultimately derived from a built-in datatype.

  • The user-derived simple type restricts a list containing simple type values.

  • The user-derived simple type restricts a union whose member types are other simple types.

For simple types ultimately derived as a restriction of a built-in datatype—as opposed to a list or union—the constraining facets apply to the base datatype. A constraining facet limits the values that are permissible in an XML instance. These limits are in addition to those constraining facets already associated with the base simple type. For example, the partNameType introduced in Listing 10.1 is a refinement, or restriction, of the built-in token type. Similarly, the values permissible for the assemblyPartNumberType presented in Listing 10.3 are constrained further than the partNumberType in Listing 10.2. Chapter 12 discusses constraining facets in detail.

Sections 10.7.3 and 10.8.3 illuminate the constraining facets of the list and union elements, respectively.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.70.157