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

Hi,

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:restriction>
    <xs:simpleType>
      <xs:list itemType="xs:date" />
    </xs:simpleType>
    <xs:minLength value="0" />
    <xs:maxLength value="1" />
  </xs:restriction>
</xs:simpleType>

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" />

with:

<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.
  
Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/
Received on Wednesday, 20 November 2002 13:22:45 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:35 GMT