我正在写一个XSD。如果我有这样的元素,我想将Value
的默认值设置为整数。看起来如果元素具有一个范围的数字,我可以执行此操作,但是如果具有如下所示的多个范围,则无法向添加默认值Value
。有没有一种方法可以向定义了多个范围的元素添加默认值?我认为这是不允许的类型,xs:union
但我确定该怎么做才能获取默认值和一组范围。
<xs:element name="Value" default="20">
<xs:annotation>
<xs:documentation xml:lang="en">
Some Random Annotation
</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:union>
<xs:simpleType>
<xs:restriction base='xs:integer'>
<xs:minInclusive value="20"/>
<xs:maxInclusive value="30"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base='xs:integer'>
<xs:minInclusive value="40"/>
<xs:maxInclusive value="54"/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>
您可以具有联合的默认值,只要它与联合定义的类型一致即可。在这种情况下,默认值20满足第一个简单类型的约束,因此很好。如果默认值为200,则不允许使用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句