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

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 UTC