W3C home > Mailing lists > Public > xmlschema-dev@w3.org > January 2001

Re: Simple question on elements constraints

From: Henry S. Thompson <ht@cogsci.ed.ac.uk>
Date: 24 Jan 2001 08:41:39 +0000
To: Michael Anderson <michael@research.canon.com.au>
Cc: Adalbert Wysocki <waldi@imediation.com>, xmlschema-dev@w3.org
Message-ID: <f5bzogh2vgc.fsf@cogsci.ed.ac.uk>
Michael Anderson <michael@research.canon.com.au> writes:

> Adalbert Wysocki wrote:
> 
> > Hi all,
> > I have a very simple question but it better to ask experienced people
> > rather than write dirty thinks.
> > The context is the validation of XML documents using XMLSchema.
> > How can I specify that an element must have a fixed value and cannot
> > have an empty one.
> >
> > example:
> > -------
> > <?xml version="1.0"?>
> > <contract>
> >   <id></id>
> > </contract>
> >
> > This document is not valid because the element 'id' is empty whereas
> > it should be filled with a value and this value equals for example
> > '3000'.
> >
> > I tryed following:
> > .....
> > <xsd:element name="id" type="noEmptyElement" fixed="3000"/>
> > ....
> > <xsd:simpleType name="noEmptyElement">
> >   <xsd:restriction base="xsd:string">
> >     <minLength value="1"/>
> >   </xsd:restriction>
> > </xsd:simpleType>
> > ...
> 
> Quoting from Structures 3.3
> "If fixed is specified, then the element's content must either be empty,
> in which case fixed behaves as default, or it must match the supplied
> constraint string"
> 
> So IMO, it comes down to what is -
> <id></id>
> If this is an _empty_string_ but not an _empty_content_, then this
> instance should fail your schema and the validator should pick this up
> (as you want it to).  I believe that this is the case as in order to
> specify an _empty_content_ one should use the xsi:null="true" in the
> instance.  In which case, if you want to have instances being forced to
> write "3000" and not allowing _empty_content_, just have
> <xsd:element name="id" type="xsd:string" nullable="false" fixed="3000"/>
> 
> or, using defaults, just
> <xsd:element name="id" fixed="3000"/>
> 
> However, this is just my interpretation of the quote above "element's
> content must either be empty,".  There are a few ways this could be
> interpreted

Sorry, you're reading too much into this:  empty means no content,
that's all, so your example above is fine and will attract the
default, thereby defeating the stated intent of the author of the
original question.> 

> This analysis assumes that <id></id> is an empty string and not an empty
> content.

This distinction doesn't really exist in the way you're suggesting.

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 Wednesday, 24 January 2001 03:41:49 GMT

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