开发者

XML Schema, One of each child element?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜