Re: Simple question on elements constraints

On the first point:  David Cleary had made the assumption that the desire
was for an integer which happened to be 3000.  Adalbert Wysocki will have
to tell us if this is fundamentally an integer or a string.  If it is an
integer, and David is right, then it's probably better to derive from
integer as David did so that it's obvious to all Schema tools, and then he
would have to use a pattern restriction to avoid allowing other forms of
the number 3000 (of course Adalbert will also have to tell us if he minds
those.  I made that assumption.)  If it's really a string, then I agree
that the best solution is restriction string with an enumeration as Francis
Norton did below.

On your second point:  I don't see anything at your link saying that
"fixed" and "default" apply only to attributes.  I believe that they apply
to elements as well, see [1].

[1] http://www.w3.org/TR/xmlschema-1/#Element_Declaration_details



Francis Norton <francis@redrice.com> on 01/24/2001 07:18:23 AM

Please respond to francis@redrice.com

To:   Adalbert Wysocki <waldi@imediation.com>
cc:   xmlschema-dev@w3.org
Subject:  Re: Simple question on elements constraints




Albert,

I think there are two questions here. First, how to specify a fixed,
non-empty value for a mandatory element.

This can be done using an enumeration (see
http://www.w3.org/TR/xmlschema-0/#ref10), eg:

<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
elementFormDefault="qualified">
  <xsd:element name="root">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="fred" type="fixedNotEmpty"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:simpleType name="fixedNotEmpty">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="3000"/>
    </xsd:restriction>
  </xsd:simpleType>
</xsd:schema>

The second question has to do with defaults. "fixed" and "default" only
apply to attribute declarations (see
http://www.w3.org/TR/xmlschema-0/#ref36) and are specified via the "use"
and "value" attributes, eg you could add:

      <xsd:attribute name="weather" use="fixed" value="wet" />

after the </xsd:sequence> above, and while both XML Spy 3.5 and xsv will
allow the "weather" attribute to be absent, neither will allow it to be
empty or to have any value but "wet".

Hope this helps -

Francis.

Received on Wednesday, 24 January 2001 10:31:13 UTC