views:

112

answers:

1

I came across a legacy XSD that has a bunch of lines like...

      <xs:element minOccurs="1"
                  maxOccurs="1"
                  default="true"
                  name="Ready" type="xs:boolean" />

...where minOccurs and maxOccurrs both equal 1, AND there is a default value. Is there any benefit to having the default attribute here since the XML doc is required to contain some value any way?

+4  A: 

From the spec:

The schema processor treats defaulted elements slightly differently. When an element is declared with a default value, the value of the element is whatever value appears as the element's content in the instance document; if the element appears without any content, the schema processor provides the element with a value equal to that of the default attribute. However, if the element does not appear in the instance document, the schema processor does not provide the element at all. In summary, the differences between element and attribute defaults can be stated as: Default attribute values apply when attributes are missing, and default element values apply when elements are empty.

I take this to mean that an empty <Ready /> node would default to a value of TRUE based on your schema.

zac