O'Reilly logo

Real World XML by Steven Holzner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required