W3C home > Mailing lists > Public > xmlschema-dev@w3.org > November 2002

Re: IS it possible to have a blank date element

From: Jeni Tennison <jeni@jenitennison.com>
Date: Wed, 20 Nov 2002 18:22:42 +0000
Message-ID: <166-2132611033.20021120182242@jenitennison.com>
To: xmlschema-dev@w3.org
CC: helen.mauger@rawlinson-hunter.gg


Stefan Wachter wrote:
> Maybe you can use a union type:
> <simpleType name="DateOrEmpty">
>   <memberTypes="date">
>     <simpleType>
>       <restriction base="string">
>         <length value="0"/>
>       </restriction>
>     <simpleType>
>   </memberType>
> </simpleType>
> <element xsi:type="DateOrEmpty"/>
> should now be valid.

I think that creating a list type that holds 0 or 1 xs:date values
would be better:

<xs:simpleType name="optionalDate">
      <xs:list itemType="xs:date" />
    <xs:minLength value="0" />
    <xs:maxLength value="1" />

It makes no difference in terms of validation, but in XPath 2.0 it
would mean that the element held an empty sequence if the date was
omitted, rather than holding an empty string in that case, which I
think more accurately reflects what the element holds.

But I think that Dare's suggestion of using nillable and xsi:nil also
does the trick:

<xs:element name="date" nillable="true" type="xs:date" />


<date xsi:nil="true" />

when the date is missing for whatever reason, but this requires
something to be added to the instance document to indicate a missing
value, which may or may not be possible.

Making the element *itself* optional:

  <xs:element name="date" type="xs:date" minOccurs="0" />

and omitting the <date> element entirely when the value is missing is
another design option.


Jeni Tennison
Received on Wednesday, 20 November 2002 13:22:45 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:15:07 UTC