[Home] [By Thread] [By Date] [Recent Entries]


Title: RE: XML-Schema Help
Sorry, I was just copy/pasting. Remove the "minOccurs" then, or even embed the choice elements in their own sequence with a minOccurs of 1.
 
-BKN
 
----- Original Message -----
Sent: Friday, August 16, 2002 11:40 AM
Subject: RE: XML-Schema Help

I believe this will not work because the schema would be non-determinstic.  That is, because the following declaration:

      <xs:element ref="earliestdate" minOccurs="0"/>

appears in two different "choice" constructs, a schema processor will not be able to discern whether an occurrence of "earliestdate" is applicable to the first "choice" construct or the second one.  Same idea for "latestdate".

Regards,
Joe Chiusano
LMI

> **************************************************************************
>   Joseph M. Chiusano
>   Logistics Management Institute
>   2000 Corporate Ridge
>   McLean, VA 22102
>   Email: jchiusano@l...
>   Tel: 571.633.7722
> **************************************************************************
>


-----Original Message-----
From: Bryce K. Nielsen [mailto:bryce@s...]
Sent: Friday, August 16, 2002 1:30 PM
To: xml-dev@l...
Subject: Re: XML-Schema Help


> My question is this, in a Schema is it possible to have an element be
> required only if its parent element exists.
>
> For example in the code below if timeframetype exists then either
> earliestdate or latestdate would be required, 1 or the other but both are
> not required.
>
> <xs:complexType name="timeframeType">
> <xs:sequence>
> <xs:element ref="description"/>
> <xs:element ref="earliestdate" minOccurs="0"/>
> <xs:element ref="latestdate" minOccurs="0"/>
> </xs:sequence>
> </xs:complexType>
>

There are a lot of different ways you could do this, but here's a go:

<xs:complexType name="timeframeType">
  <xs:sequence>
    <xs:element ref="description"/>
    <xs:choice>
      <xs:element ref="earliestdate" minOccurs="0"/>
      <xs:element ref="latestdate" minOccurs="0"/>
    </xs:choice>

    <xs:choice>
      <xs:element ref="earliestdate" minOccurs="0"/>
    </xs:choice>

    <xs:choice>
      <xs:element ref="latestdate" minOccurs="0"/>
    </xs:choice>
  </xs:sequence>
</xs:complexType>

you could refactor this into groups for easier reading...

-BKN


-----------------------------------------------------------------
The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
initiative of OASIS <http://www.oasis-open.org>

The list archives are at http://lists.xml.org/archives/xml-dev/

To subscribe or unsubscribe from this list use the subscription
manager: <http://lists.xml.org/ob/adm.pl>


Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member