TeaOverflow
TeaOverflow

Reputation: 2578

XML Schema maxOccurs and xs:all

I got the following schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
  <xs:element name="machine">
    <xs:complexType>
    <xs:sequence>
      <xs:element name="states" type="tokenList"/>
      <xs:element name="in_alphabet" type="tokenList"/>
      <xs:element name="blank" type="xs:string"/>
      <xs:element name="tape_alphabet" type="tokenList"/>
      <xs:element name="first_state" type="xs:string"/>
      <xs:element name="final_states" type="tokenList"/>

      <xs:element name="delta" type="delta_func" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:simpleType name="tokenList">
    <xs:list itemType="xs:normalizedString"/>
  </xs:simpleType>

  <xs:complexType name="delta_func">
    <xs:sequence>
      <xs:element name="state" type="xs:string"/>
      <xs:element name="read" type="xs:string"/>
      <xs:element name="target_states" type="tokenList"/>
      <xs:element name="write" type="xs:string"/>
      <xs:element name="move">
        <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:pattern value="R|L|r|l"/>
        </xs:restriction>
        </xs:simpleType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>

</xs:schema>

Which works, but I would like to not restrict the order of the elements. I tried xs:all but it doesn't allow maxOccurs=unbounded for delta, which is a must. All other elements occur only once, so xs:all wouldn't be problem here. Is there a way to define random order on the element while allowing an unlimited numbers of deltas?

Upvotes: 3

Views: 2807

Answers (2)

Michael Kay
Michael Kay

Reputation: 163665

XSD 1.1 allows what you are looking for: xs:all with a maxOccurs on each element particle.

Upvotes: 4

forty-two
forty-two

Reputation: 12817

Instead of <sequence>, you could use <choice maxOccurrs="unbounded">, but it would imply that all elements can occur more than once.

Upvotes: 4

Related Questions