Specifying Attribute Constraints and Defaults

As with elements, you can specify the type of attributes, but unlike elements, attributes must be of a simple type. And you don't use minOccurs and maxOccurs for attributes because attributes can appear only once, at most. Instead, you use a different syntax when constraining attributes.

You declare attributes with the <xsd:attribute> element, and the <xsd:attribute> element itself has a type attribute that gives the attribute's (simple) type. So how do you indicate whether an attribute is required or optional, or whether there's a default value, or even whether the value of the attribute is fixed at a certain value? You use the <xsd:attribute> element's use and value attributes.

The use attribute ...

Get Real World XML now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.