2014-04-04 31 views
1

我有一个名为SafetyTiming的复杂类型,它有2个元素值和余量。价值和保证金都是基于一种称为Timing的简单类型。更改复杂类型内的类型的最小限制

<xs:simpleType name="Timing"> 
    <xs:restriction base="xs:unsignedInt"> 
     <xs:minInclusive value="0" /> 
     <xs:maxInclusive value="999" /> 
    </xs:restriction> 
    </xs:simpleType> 

    <xs:complexType name="SafetyTiming"> 
    <xs:sequence> 
     <xs:element name="Value" type="Timing" minOccurs="1" maxOccurs="1" /> 
     <xs:element name="Margin" type="Timing" minOccurs="1" maxOccurs="1" /> 
    </xs:sequence> 
    </xs:complexType> 

    <xs:element name="SafetyTimings"> 
    <xs:complexType> 
     <xs:all> 
     <xs:element name="A" type="SafetyTiming" minOccurs="1" maxOccurs="1" /> 
     <xs:element name="B" type="SafetyTiming" minOccurs="1" maxOccurs="1" /> 
     <xs:element name="C" type="SafetyTiming" minOccurs="1" maxOccurs="1" /> 
     <xs:element name="D" type="SafetyTiming" minOccurs="1" maxOccurs="1" /> 
     </xs:all> 
    </xs:complexType> 
    </xs:element> 

这是细直到我发现,元件A和B必须为的simpleType“值” a最小值为0,,C和d的最小的1

如何可以完美地解决这个?


我试过以下,但我认为它看起来相当混乱,我不知道是否有更好的解决方案。

<!--Safety timing type containing the timing value (minimum 0) and the value margin--> 
    <xs:complexType name="SafetyTiming_min0"> 
    <xs:sequence> 
     <xs:element name="Value" type="Timing" minOccurs="1" maxOccurs="1" /> 
     <xs:element name="Margin" type="Timing" minOccurs="1" maxOccurs="1" /> 
    </xs:sequence> 
    </xs:complexType> 

    <!--Safety timing type containing the timing value (minimum 1) and the value margin--> 
    <xs:complexType name="SafetyTiming_min1"> 
    <xs:sequence> 
     <xs:element name="Value" minOccurs="1" maxOccurs="1"> 
     <xs:simpleType> 
      <xs:restriction base="Timing"> 
      <xs:minInclusive value="1" /> 
      </xs:restriction> 
     </xs:simpleType> 
     </xs:element> 
     <xs:element name="Margin" type="Timing" minOccurs="1" maxOccurs="1" /> 
    </xs:sequence> 
    </xs:complexType> 

回答

0

您可以从Timing派生限制类型:

<xs:simpleType name="CDTiming"> 
    <xs:restriction base="Timing"> 
     <xs:minInclusive value="1" /> 
    </xs:restriction> 
</xs:simpleType> 

所以,很简单,只是创建一个新的类型为CD已限制Value

<xs:complexType name="CDSafetyTiming"> 
    <xs:sequence> 
     <xs:element name="Value" type="CDTiming" minOccurs="1" maxOccurs="1" /> 
     <xs:element name="Margin" type="Timing" minOccurs="1" maxOccurs="1" /> 
    </xs:sequence> 
</xs:complexType> 

你不自原始类型以来,不需要为AB更改任何内容已经有至少0

如果你可以改变你原来的XSD,您可以在元素的定义中使用的新类型:

<xs:element name="SafetyTimings"> 
    <xs:complexType> 
     <xs:all> 
      <xs:element name="A" type="SafetyTiming" minOccurs="1" maxOccurs="1" /> 
      <xs:element name="B" type="SafetyTiming" minOccurs="1" maxOccurs="1" /> 
      <xs:element name="C" type="CDSafetyTiming" minOccurs="1" maxOccurs="1" /> 
      <xs:element name="D" type="CDSafetyTiming" minOccurs="1" maxOccurs="1" /> 
     </xs:all> 
    </xs:complexType> 
</xs:element> 
+0

没错,就是这样做的另一种方式。我只是希望没有创建另一个定时或SafetyTiming对象的方法。就像直接向xs:元素C和D添加新的限制一样。 –