开发者

Trouble defining a list of elements in a xsd file when elements repeat

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"/>
  <RecordEn开发者_StackOverflow中文版try 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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜