W3C home > Mailing lists > Public > xmlschema-dev@w3.org > December 2000

Re: [Moderator Action] Re: [Moderator Action] How to define an element which must have a value?

From: Henry S. Thompson <ht@cogsci.ed.ac.uk>
Date: 18 Dec 2000 17:11:56 +0000
To: Jingkun Hu <hujingkun@yahoo.com>
Cc: xmlschema-dev@w3.org
Message-ID: <f5br9358xib.fsf@cogsci.ed.ac.uk>
Jingkun Hu <hujingkun@yahoo.com> writes:

> What I need is to derive some types which must have a
> valid value and some other 
> type that allow no value, for example, 
> 
> <element name="PatientBirthDate">
>     <complexType>
>         <restriction base="date">
>             <pattern
> value="[12][0-9]{3}-[0-1][0-9]-[0-3][0-9]"/>
>         </restriction>
>    </complexType>
> </element>
> 
> In this example, a mandatory requirement is that PatientBirthDate
> must have a valid birth date.  Is this definition enough?

Yes, except where you have <complexType> you probably want
<simpleType>.

If I'm not mistaken, your pattern facet is redundant, in that it
doesn't enforce any restriction beyond what is already in place in the 
primitive builtin 'date' type.

> In the following example,
> 
> <element name="EmployeeBirthDate">
>     <complexType>
>         <restriction base="date">
>             <pattern
> value="[12][0-9]{3}-[0-1][0-9]-[0-3][0-9]"/>
>         </restriction>
>    </complexType>
> </element>
> 
> Employee may have an empty birthdate, is this
> definition OK?

No.  You need to either mark the element as 'nullable="true"' and
instances without birthdates as <EmployeeBirthDate xsi:null='true'/>,
or make the EmployeeBirthDate _itself_ optional, or use a union type
with the empty string.  Which you choose depends on both the form of
your existing legacy data, if any, and the anture of your application.

> Also, could you recommend me a good XML schema validator?

See the list at http://www.w3.org/XML/Schema.html

ht
-- 
  Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
          W3C Fellow 1999--2001, part-time member of W3C Team
     2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
	    Fax: (44) 131 650-4587, e-mail: ht@cogsci.ed.ac.uk
		     URL: http://www.ltg.ed.ac.uk/~ht/
Received on Monday, 18 December 2000 12:11:59 GMT

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