开发者

XML Schema, One of each child element?

开发者 https://www.devze.com 2023-01-21 05:00 出处:网络
I want to define a schema that allows child elements to occur in any order, similar to <choice minOccurs=\"0\" maxOccurs=\"unbounded\"> but will allow o开发者_JS百科nly one of each element, simi

I want to define a schema that allows child elements to occur in any order, similar to <choice minOccurs="0" maxOccurs="unbounded"> but will allow o开发者_JS百科nly one of each element, similar to <sequence minOccurs="1" maxOccurs="1">

can this be done?

for example

<Root>
 <ele1>
 <ele3>
 <ele2>
</Root>    <!--Valid-->

And as below:

<Root>
 <ele1>
 <ele1>
 <ele3> 
</Root> <!--Invalid-->


Use xs:all rather than xs:sequence, so you'd write:

<xs:element name="Root">
    <xs:complexType>
            <xs:all>
                <xs:element name="element1"/>
                <xs:element name="element2"/>
                <xs:element name="element3"/>
            </xs:all>
    </xs:complexType>
</xs:element>


You can add maxOccurs="1" to the element.

0

精彩评论

暂无评论...
验证码 换一张
取 消