简体   繁体   中英

XML Schema construct for “Any number of these elements - in any order”

I need to create an XML schema that looks something like this:

<xs:element name="wrapperElement">
<xs:complexType>
    <xs:sequence>
        <xs:element type="el1">
        <xs:element type="el2">
    </xs:sequence>

    <xs:WhatGoesHere?>
        <xs:element type="el3"> 
        <xs:element type="el4">
        <xs:element type="el5">
    </xs:WhatGoesHere?>

    <xs:sequence>
        <xs:element type="el6">
        <xs:element type="el7">
    </xs:sequence>
</xs:complexType>
</xs:element>

What I need is a replacement for "WhatGoesHere" such that any number of el3, el4 and el5 can appear in any order. For instance it could contain {el3, el3, el5, el3}

Any idea on how to solve this?

You want xs:choice with occurrence constraints:

<xs:element name="wrapperElement">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="e11"/>
      <xs:element name="el2"/>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="el3"/>
        <xs:element name="el4"/>
        <xs:element name="el5"/>
      </xs:choice>
      <xs:element name="el6"/>
      <xs:element name="el7"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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