简体   繁体   English

一个元素多次

[英]One element multiple times

I want to be able to specify one element, in my case Param , multiple times. 我希望能够多次指定一个元素,例如我的Param This is the XSD: 这是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>

This is the corresponding XML: 这是相应的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>

Trying this, I get the following exception: 尝试此操作,出现以下异常:

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.

The xsd:all only allows 0 or 1 occurrence of any of it children. xsd:all仅允许0或1次出现任何它的子级。

You could use an xsd::sequence instead.. but know that in that case any element in they are defined in the order in which they must appear in the xml. 您可以改用xsd :: sequence ..但知道在这种情况下,它们中的任何元素都是按照它们在xml中出现的顺序定义的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM