0
votes

Below are 2 examples of XML files

<Parent>
    <Child1>
        <Child2> value</Child2>
        <Child1>
            <Child2>value<Child2>
            <Child3> value </Child3>
            <Child4> value </Child4>
        </Child1>
        <Child1>
            <Child2>value<Child2>
            <Child4> value </Child4>
        </Child1>
    </Child1>
</Parent> 

<Parent>
    <Child1>
        <Child2> value</Child2>
        <Child3> value </Child3>
        <Child1>
            <Child4> value </Child4>
            <Child2>value<Child2>
            <Child3> value </Child3>
        </Child1>
    </Child1>
</Parent>

The elements can be in any order and there any number of sequences as well

The schema is defined as:

<xs:complexType name="Child1">
    <xs:sequence minOccurs="0" >
      <xs:element type="xs:string" name="Child2" minOccurs="0" maxOccurs="unbounded" />
      <xs:element type="xs:string" name="Child3" maxOccurs="unbounded" minOccurs="0" />
      <xs:element type="xs:string" name="Child1" minOccurs="0" maxOccurs="unbounded" />
      <xs:element type="xs:string" name="Child4" maxOccurs="unbounded" minOccurs="0" />
    </xs:sequence>
</xs:complexType>

<xs:complexType name="Parent">
    <xs:sequence>
      <xs:element type="Child1" name="Child1" maxOccurs="unbounded" minOccurs="0" />
    </xs:sequence>
  </xs:complexType>

The issue I am having is: 1. The elements can be in different order. But since I have set it as xs:sequence it is required to be in a specific order 2. If I change to xs:all so that it allows different order of elements, then I cannot set maxOccurs as unbounded as that is not allowed for xs:all.

Is there a way to allow both different order of elements and maxOcurance as unbounded?

1

1 Answers

2
votes

You can try xs:choice:

`

<xs:complexType name="Child1">
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element type="xs:string" name="Child2" />
      <xs:element type="xs:string" name="Child3" />
      <xs:element type="xs:string" name="Child1"/>
      <xs:element type="xs:string" name="Child4" />
    </xs:choice>
</xs:complexType>

`