当 minOccurs 属性 > 时使用默认属性的任何好处1? [英] Any benefit to using default attribute when minOccurs attribrute is > 1?

查看:18
本文介绍了当 minOccurs 属性 > 时使用默认属性的任何好处1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个旧的 XSD,它有一堆像......的行

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

...其中 minOccurs 和 maxOccurrs 都等于 1,并且有一个默认值.由于 XML 文档需要以任何方式包含某些值,因此在此处使用默认属性是否有任何好处?

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

推荐答案

来自 spec:

模式处理器处理默认值元素略有不同.当一个元素用默认值声明value,元素的值是任何值显示为实例中元素的内容文档;如果元素出现没有任何内容,架构处理器为元素提供了一个值等于默认值属性.但是,如果元素没有出现在实例中文档,模式处理器执行根本不提供元素.在总结,两者的区别元素和属性默认值可以是表述为:默认属性值当属性缺失时应用,以及元素为空时应用默认元素值.

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.

我认为这意味着空 <Ready/> 节点将根据您的架构默认值为 TRUE.

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

这篇关于当 minOccurs 属性 > 时使用默认属性的任何好处1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆