2017-07-13 108 views
0

假设我有一个属性类型,允许的(0,1,2,3),即所有的组合中的任何值:XSD类型限制继承?

<xs:simpleType name="fourValues"> 
    <xs:restriction base="xs:string"> 
     <xs:enumeration value="0" /> 
     <xs:enumeration value="1" /> 
     <xs:enumeration value="2" /> 
     <xs:enumeration value="3" /> 
     <xs:enumeration value="0,1" /> 
     <xs:enumeration value="0,2" /> 
     <xs:enumeration value="0,3" /> 
     <xs:enumeration value="0,4" /> 
     <xs:enumeration value="1,2" /> 
     <xs:enumeration value="1,3" /> 
     <xs:enumeration value="2,3" /> 
     <xs:enumeration value="0,1,2" /> 
     <xs:enumeration value="0,1,3" /> 
     <xs:enumeration value="0,2,3" /> 
     <xs:enumeration value="1,2,3" /> 
     <xs:enumeration value="0,1,2,3" /> 
    </xs:restriction> 
    </xs:simpleType> 

现在,如果我想定义一个类型,它是与上述相同的什么,但也允许空(NULL)值,如:

<xs:simpleType name="fourValues-null"> 
    <xs:restriction base="xs:string"> 
     <xs:enumeration value="" /> 
     <xs:enumeration value="0" /> 
     <xs:enumeration value="1" /> 
     <xs:enumeration value="2" /> 
     <xs:enumeration value="3" /> 
     <xs:enumeration value="0,1" /> 
     <xs:enumeration value="0,2" /> 
     <xs:enumeration value="0,3" /> 
     <xs:enumeration value="0,4" /> 
     <xs:enumeration value="1,2" /> 
     <xs:enumeration value="1,3" /> 
     <xs:enumeration value="2,3" /> 
     <xs:enumeration value="0,1,2" /> 
     <xs:enumeration value="0,1,3" /> 
     <xs:enumeration value="0,2,3" /> 
     <xs:enumeration value="1,2,3" /> 
     <xs:enumeration value="0,1,2,3" /> 
    </xs:restriction> 
    </xs:simpleType> 

是否有某种类型的继承,避免我列举的重复这两种类型的?

我有两个属性的使用:

<xs:attribute name="readingSources" type="fourValues" use="required" /> 
<xs:attribute name="targetFlip" type="fourValues-null" use="required"> 

我试图让targetFlip属性type="fourValues"use="optional"但它说,限制失败。

回答

1

这样做的一种方法是定义允许将额外值作为顶级类型的新类型,然后重新定义现有类型作为其限制条件,并带有诸如<minLength value="1"/>等额外方面。

第二种方法是将新类型定义为现有类型的联合类型和仅允许零长度字符串的类型。

第三种方式(我通常喜欢的方式,但它取决于您是仅将模式用于验证还是用于数据绑定)是将新类型定义为列表类型,其中现有类型作为其项目类型,maxLength设置为1.