2013-02-20 68 views
0

我有一個XSD模式用於驗證XML文件。繼承的複雜類型中元素的順序

在XSD架構中,我創建了一個複合類型,其中包含一個屬性組和一個選項,本身包含「_output」,一個反覆出現的元素。

我的複雜類型:

<xs:complexType name="base_action"> 
    <xs:choice minOccurs="0" maxOccurs="unbounded"> 
     <xs:element name="_output" minOccurs="0" maxOccurs="unbounded"/> 
    </xs:choice> 
    <xs:attributeGroup ref="action"/> 
</xs:complexType> 

我也有其他元素(用自己的子元素)從複雜類型繼承。

這種繼承元素的爲例:現在

<xs:element name="ex_elem" minOccurs="0"> 
    <xs:complexType> 
     <xs:complexContent> 
      <xs:extension base="cockpit_base_action"> 
       <xs:choice minOccurs="0" maxOccurs="unbounded"> 
        <xs:element name="to" minOccurs="0"/> 
        <xs:element name="from" minOccurs="0"/> 
       </xs:choice> 
      </xs:extension> 
     </xs:complexContent> 
    </xs:complexType> 
</xs:element> 

,在XML中,這將工作:

<ex_elem> 
    <_output/> 
    <from>0</from> 
    <to>1</to> 
</ex_elem> 

但不是這樣的:

<ex_elem> 
    <from>0</from> 
    <_output/> 
    <to>1</to> 
</ex_elem> 

還是這個:

<ex_elem> 
    <from>0</from> 
    <to>1</to> 
    <_output/> 
</ex_elem> 

從我的理解,複雜類型的選擇不能與繼承元素的選擇混合。這對我來說是一個問題,因爲有些情況下,我想將輸出放在其他地方,而不是頂部。

我希望能夠使用該元素而不必打擾序列。有沒有辦法做到這一點?

回答

0

在XSD 1.0中,基本類型的任何擴展都會創建一個序列,其第一個成員是舊的內容模型,其第二個成員是該擴展添加到內容模型的頂部。所以你cockpit_base_action延伸的有效內容模型

<xs:sequence> 
    <xs:choice minOccurs="0" maxOccurs="unbounded"> 
    <xs:element name="_output" 
       minOccurs="0" 
       maxOccurs="unbounded"/> 
    </xs:choice> 
    <xs:choice minOccurs="0" maxOccurs="unbounded"> 
    <xs:element name="to" minOccurs="0"/> 
    <xs:element name="from" minOccurs="0"/> 
    </xs:choice> 
</xs:sequence> 

在XSD 1.1,您可以更改基本型使用的xs:所有和使用的xs:所有在擴展,得到你想要的效果。

或(在1.0或1.1中),您可以更改擴展名以接受所需的語言。像這樣的東西應該有效果,你似乎渴望:

<xs:extension base="cockpit_base_action"> 
    <xs:sequence minOccurs="0"> 
    <xs:choice> 
     <xs:element name="to"> 
     <xs:element name="from"/> 
    </xs:choice> 
    <xs:choice minOccurs="0" maxOccurs="unbounded"> 
     <xs:element name="_output"/> 
     <xs:element name="to"> 
     <xs:element name="from"/> 
    </xs:choice> 
    </xs:sequence> 
</xs:extension> 

我省略了在選擇元素的兒童發生指標,因爲它們對語言沒有影響接受:他們是一定選時包含選擇(或包含它的序列)是可選的;當含有的選擇可以這樣做時,它們可以必然地重複而不受限制。