2011-08-25 148 views
0

考慮具有屬性的元素。該屬性只能具有枚舉值。XSD元素和枚舉

是否有可能通過枚舉的值來限制這個元素的兒子?

有一個例子,因爲在禁止我的英語不是很好:)

<xs:element minOccurs="0" name="datas"> 
<xs:complexType> 
    <xs:sequence maxOccurs="unbounded"> 
     <xs:element maxOccurs="1" name="data"> 
      <xs:complexType> 
       <xs:attribute name="tag" type="xs:string" use="required"/> 
       <xs:attribute name="expr" type="xs:string" use="required"/> 
       <xs:attribute name="format" use="required"> 
        <xs:simpleType> 
         <xs:restriction base="xs:string"> 
          <xs:enumeration value="choice1"/> 
          <xs:enumeration value="choice2"/> 
          <xs:enumeration value="choice3"/> 
         </xs:restriction> 
        </xs:simpleType> 
       </xs:attribute> 
      </xs:complexType> 
      <!-- HERE IS SOME SONS --> 
      <xs:element name="element1" /> 
      <xs:element name="element2" /> 
      <xs:element name="element3" /> 
     </xs:element> 
    </xs:sequence> 
</xs:complexType> 

如果讓我選擇「選擇1」,我會在需要的部件1,和element2的/元素3。如果我選擇「choice2」,我會在要求等元素2 ...

你知道是否有可能嗎?

感謝您的回答

回答

1

這是XSD 1.1中的新功能(目前支持在近期撒克遜和Xerces的版本)。這是XSD 1.0的一個衆所周知的限制,它不能這樣做。

+0

感謝您的回答。我的一位老師向我解釋了這一點:也許wa可以使用引用的後門。例如,指定element1是對其值爲choice1的屬性的引用,並且此引用對於此屬性中每次出現的choice1值都是必需的。 – BaptX