Re: Need At-Least-One model, and CDATA element type

Hi.

> Question 1: I want to create a model such that I can have either one or
both of
> a set of elements, but not none.  The following model describes my desired
result:
>
>     <xs:choice>
>       <xs:sequence>
>         <xs:element name="StartTime" type="xs:dateTime"/>
>         <xs:element name="StopTime" type="xs:dateTime" minOccurs="0"/>
>       </xs:sequence>
>       <xs:sequence>
>         <xs:element name="StartTime" type="xs:dateTime" minOccurs="0"/>
>         <xs:element name="StopTime" type="xs:dateTime"/>
>       </xs:sequence>
>     </xs:choice>

You can't start both parts of the choice with the same element. How would a
processor know which one to choose when validating your document? DTDs have
the same restriction.

If you remove the StartTime element in the second part of the choice then
that should give you what you want.

    <xs:choice>
      <xs:sequence>
        <xs:element name="StartTime" type="xs:dateTime"/>
        <xs:element name="StopTime" type="xs:dateTime" minOccurs="0"/>
      </xs:sequence>
      <xs:sequence>
        <xs:element name="StopTime" type="xs:dateTime"/>
      </xs:sequence>
    </xs:choice>

The first part of the choice says that you must have a StartTime followed by
an optional StopTime. If the StartTime wasn't there but a StopTime was, the
second part of the choice is selected for validation. You don't need to
specify that the StartTime is optional here.

Hope this helps,
Jason.

Received on Friday, 7 September 2001 12:36:08 UTC