2014-09-11 66 views
0

我想能夠多次指定一個元素,在我的情況下爲Param。 這是XSD:一個元素多次

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:element name="Abc"> 
     <xs:complexType> 
      <xs:sequence> 
       <xs:element name="Def" minOccurs="1" maxOccurs="unbounded"> 
        <xs:complexType> 
         <xs:all> 
          <!-- ... other elements ... --> 
          <xs:element name="Param" minOccurs="0" maxOccurs="unbounded"> <!-- Using unbounded is not allowed here --> 
           <xs:complexType> 
            <xs:attribute name="Name"/> 
            <xs:attribute name="Value"/> 
           </xs:complexType> 
          </xs:element> 
          <!-- ... other elements ... --> 
         </xs:all> 
        </xs:complexType> 
       </xs:element> 
      </xs:sequence> 
     </xs:complexType> 
    </xs:element> 
</xs:schema> 

這是相應的XML:

<Abc xsi:noNamespaceSchemaLocation="SourcesSchema.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <Def> 
     <Param Name="one" Value="blue"/> 
     <Param Name="two" Value="yellow"/> 
     <Param Name="three" Value="green"/> 
    </Def > 
</Abc> 

嘗試,我得到以下異常:

Cos-all-limited.2: The {max Occurs} Of An Element In An 'all' Model Group Must Be 0 Or 1. The Value '-1' For Element 'Param' Is Invalid. 

回答

0

的XSD:一切只允許0或任何一個孩子出現1次。

你可以用一個xsd :: sequence來代替..但是知道在這種情況下,它們中的任何元素都是按照它們必須出現在xml中的順序定義的。