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

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.