开发者

Any benefit to using default attribute when minOccurs attribrute is > 1?

开发者 https://www.devze.com 2022-12-11 12:35 出处:网络
I came across a legacy XSD that has a bunch of lines like... <xs:element minOccurs=\"1\" maxOccurs=\"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" /&开发者_如何学JAVAgt;

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消