5

I'm try to design a XSD schema that allow elements to be in a random order and have maxOccurs="unbounded".

My XML:

<root>
  <key></key>
  <group></group>
  <group>
     <key></key> 
     <key></key>
     <group>
        <key></key> 
        <key></key>
     </group>
  </group> 
  <key></key>
  <key></key> 
  <group>
     <key></key> 
     <key></key>
     <key></key>
  </group>
  <key></key>
</root>
magol
  • 6,135
  • 17
  • 65
  • 120
  • 1
    Can you show us what you've managed so far? Which elements are you talking about? I'm guessing that your model allows `group` elements to contain both `key` and `group` elements and that you want `root` to have the same model. Is that right? – Nic Gibson Sep 29 '10 at 12:03

1 Answers1

5

You want <xs:choice>:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <xs:complexType name="groupType">
      <xs:choice minOccurs="0" maxOccurs="unbounded">
         <xs:element name="group" type="groupType"/>
         <xs:element name="key"/>
      </xs:choice>
   </xs:complexType>

   <xs:element name="root" type="groupType" />
</xs:schema>

I got this by pasting your sample XML into Oxygen XML editor, and using "Tools > Generate/Convert Schema", with input = your sample XML document. (It may use Trang under the covers... I'm not sure.) Then I tweaked the result.

LarsH
  • 27,481
  • 8
  • 94
  • 152