Xml Schema for repeating sequence of elements

xml, xsd

Solution

Reordering them like this seems to do it. Am I missing anything?

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:element name="Search">
        <xs:complexType>
            <xs:sequence>
              <xs:element name="Term" minOccurs="1" maxOccurs="1" type="xs:string" />
                <xs:sequence minOccurs="0" maxOccurs="unbounded">
                  <xs:element name="And" type="xs:string" />
                  <xs:element name="Term" type="xs:string" />
                </xs:sequence>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

Problem

I have xml as follows ``` <Search> <Term /> <And /> <Term /> <And /> <Term /> </Search> ``` There can be n number of Terms and n-1 Ands (n > 0) in the sequence as shown. I tried the following xml schema but above xml would not get validated against the schema. Error: cvc-complex-type.2.4.b: The content of element 'Search' is not complete. One of '{And}' is expected. ``` <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="Search"> <xs:complexType> <xs:sequence> <xs:sequence minOccurs="0" maxOccurs="unbounded"> <xs:element name="Term" type="xs:string" /> <xs:element name="And" type="xs:string" /> </xs:sequence> <xs:element name="Term" minOccurs="1" maxOccurs="1" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> ``` Appreciate any help with the xml schema.

Original source