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

Re: Simple question on elements constraints

From: Francis Norton <francis@redrice.com>
Date: Wed, 24 Jan 2001 12:18:23 +0000
Message-ID: <3A6EC80F.FD53E8EF@redrice.com>
To: Adalbert Wysocki <waldi@imediation.com>
CC: xmlschema-dev@w3.org
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 07:20:48 GMT

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