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 07:20:48 UTC