开发者

How to define xsd restrinction xs:enumeration to also accept empty element?

I have xsd schema that define Gender element that accepts only F or M value but I want it also to accept empty <Gender/> element. How to fix following schema?

...
<xs:simpleTyp开发者_开发百科e name="Gender">        
        <xs:restriction base="xs:string">
            <xs:enumeration value="M" />
            <xs:enumeration value="F" />
        </xs:restriction>
</xs:simpleType>
...


Have you tried adding:

<xs:enumeration value="" />

?

However, this is bad practice. If you want to represent this information in the instance documents, you should omit the <Gender> element altogether, rather than providing an empty one. Also, it's unclear what <Gender/> means - does this mean "no gender", or "unknown gender"? If it's one of those possibilities, perhaps you should add those to the eneration:

<xs:simpleType name="Gender">        
        <xs:restriction base="xs:string">
            <xs:enumeration value="M" />
            <xs:enumeration value="F" />
            <xs:enumeration value="unknown" />
        </xs:restriction>
</xs:simpleType>


You could use a pattern instead:

<xs:simpleType name="Gender">        
   <xs:restriction base="xs:string">
      <xs:pattern value="(M|F)?"/>
   </xs:restriction>
</xs:simpleType>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜