XSD - 允许元素类型为整数或为空 [英] XSD - allow element type as integer OR empty
本文介绍了XSD - 允许元素类型为整数或为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要能够将简单元素类型设置为整数,但也允许它为空.如果此示例为空且空白字段不是整数,则此示例发送错误.我怎样才能绕过这个?
I need to be able to set a simple element type as an integer but allow it to also be empty. This example sends an error if its empty and a blank field is not an integer. How can I get round this?
<xsd:element name="weight" type="xsd:integer"/>
推荐答案
你要做的就是对同一个元素分配限制,并在它们上建立一个联合,例如下面的例子:
What you have to do is assign restrictions on the same element plus make a union on them such as the following example:
<xs:element name="job_code">
<xs:simpleType>
<xs:union>
<xs:simpleType>
<xs:restriction base='xs:string'>
<xs:length value="0"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base='xs:integer' />
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>
通过使用此限制,您可以告诉 xml 验证允许任何整数值,如果元素为空,则允许该元素.
By using this restriction, you tell the xml validation to allow any integer value and allowing the element if it is empty.
这篇关于XSD - 允许元素类型为整数或为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文