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

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"
  <xsd:element name="root">
        <xsd:element name="fred" type="fixedNotEmpty"/>
  <xsd:simpleType name="fixedNotEmpty">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="3000"/>

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 -

Received on Wednesday, 24 January 2001 07:20:48 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:14:49 UTC