[英]One element multiple times
我希望能夠多次指定一個元素,例如我的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.
xsd:all僅允許0或1次出現任何它的子級。
您可以改用xsd :: sequence ..但知道在這種情況下,它們中的任何元素都是按照它們在xml中出現的順序定義的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.