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 Default Values for Elements

In addition to the minOccurs and maxOccurs attributes, you can use the <xsd:element> element's fixed and default attributes to indicate values that an element must have (you use one of these attributes, not both together). For example, setting fixed to 400 means that the element's value must always be 400. Setting the default value to 400, on the other hand, means that the default value for the element is 400, but if the element appears in the document, its actual value is the value it encloses.

For example, here I'm setting the value of an element named <maxTrials> to 100 and specifying that it must always be 100, using the fixed attribute in the <xsd:element> element:

 <xsd:element name="maxTrials" type="xsd:integer" ...

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