Question

I am trying to write a xsd file to validate my xml. Here is a sample of the xml

<Record xmlns="http://example.com/FixedBinaryFile.xsd" Name="Clients">
  <Padding Size="5">
  <RecordEntry Name="Foo1" DataType ="Char"/>
  <RecordEntry Name="Foo2" DataType="AnsiString" MaxSize="8"/>
  <RecordEntry Name="Foo3" DataType="AnsiString" MaxSize="25"/> 
  <Padding Size="2"/> 
  <RecordEntry Name="Foo4" DataType="Byte"/>
  <Padding Size="1"/> 
  <RecordEntry Name="Foo5" DataType="UInt16"/>
  <RecordEntry Name="Foo6" DataType="AnsiString" MaxSize="3"/>
  <RecordEntry Name="Foo7" DataType="AnsiString" MaxSize ="3"/>
  <Padding Size="22"/>
</Record>

and here is the xsd that defines it

  <xs:element name="Record">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="RecordEntry" type="RecordEntry" minOccurs="1" maxOccurs="unbounded"/>
        <xs:element name="Padding" type ="PaddingEntry" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
      <xs:attribute name="Name" type="xs:string" use ="required"/>
    </xs:complexType>
  </xs:element>

My problem is sequence does not allow me to put padding entries where ever I want (right now I can have as many RecordEntry entries as I want followed by as many Padding entries as i want).

My inital thought was to use all instead of sequence. However it won't let me use all with maxOccurs

What do I need to do to define my list correctly?

EDIT: Freek had it right, here is what I had to change it to to make it work.

  <xs:element name="Record">
    <xs:complexType>
      <xs:sequence minOccurs="1" maxOccurs="unbounded">
        <xs:element name="Padding" type ="PaddingEntry" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element name="RecordEntry" type="RecordEntry" minOccurs="0" maxOccurs="unbounded"/>
      </xs:sequence>
      <xs:attribute name="Name" type="xs:string" use ="required"/>
    </xs:complexType>
  </xs:element>
Was it helpful?

Solution

You can also set minOccurs and maxOccurs on the xs:sequence, setting that to appropriate values (probably minOccurs="0" maxOccurs="unbounded") should solve your problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top