I am currently having a problem with an XSD. Normally an entry looks like this:
<Entry Num="4">
<Info>
<Name>Something</Name>
<ID>1234</ID>
<Start>2013-01-07</Start>
<Stop>2013-01-09</Stop>
<Completed>6</Completed>
</Info>
</Entry>
But occasionally it will look like this:
<Entry Num="5">
<Info>
<Name>SomethingElse</Name>
<ID>5678</ID>
<Start>2013-01-08</Start>
<Stop>2013-01-10</Stop>
<Start>2013-01-11</Start>
<Stop>2013-01-12</Stop>
<Completed>14</Completed>
</Info>
</Entry>
To try and capture the potential for multiple Starts and Stops I tried the following things:
<xs:sequence maxOccurs="unbounded">
<xs:element name="Start" type="xs:dateTime" maxOccurs="1"/>
<xs:element name="Stop" type="xs:dateTime" maxOccurs="1"/>
</xs:sequence>
<xs:sequence maxOccurs="unbounded">
<xs:element name="Start" type="xs:dateTime" />
<xs:element name="Stop" type="xs:dateTime" />
</xs:sequence>
<xs:sequence maxOccurs="unbounded">
<xs:sequence>
<xs:element name="Start" type="xs:dateTime" />
<xs:element name="Stop" type="xs:dateTime" />
</xs:sequence>
</xs:sequence>
<xs:sequence maxOccurs="unbounded">
<xs:sequence>
<xs:element name="Start" type="xs:dateTime" maxOccurs="1"/>
<xs:element name="Stop" type="xs:dateTime" maxOccurs="1"/>
</xs:sequence>
</xs:sequence>
But they all resulted in an array of Starts which are printed followed by an array of Stops when I converted it to C# classes using xsd.exe which serialized to this:
<Entry Num="5">
<Info>
<Name>SomethingElse</Name>
<ID>5678</ID>
<Start>2013-01-08</Start>
<Start>2013-01-11</Start>
<Stop>2013-01-10</Stop>
<Stop>2013-01-12</Stop>
<Completed>14</Completed>
</Info>
</Entry>
And this doesn't match the XML file. Does anyone know how to do something like this properly? Thanks a lot.
I came up with a solution that works, but isn't ideal.
Current Solution:
<xs:choice minOccurs="2" maxOccurs="unbounded">
<xs:element name="Start" type="xs:dateTime"/>
<xs:element name="Stop" type="xs:dateTime"/>
</xs:choice>