2013-02-20 69 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> 

我省略了在选择元素的儿童发生指标,因为它们对语言没有影响接受:他们是一定选时包含选择(或包含它的序列)是可选的;当含有的选择可以这样做时,它们可以必然地重复而不受限制。