Identity versus Equality in enumerations and fixed value constraints

In the call today we decided to use identity for value constraints, just  
as we
do for enumeration, on the logic that a fixed value constraint is like an
enumeration with a single value.

Noah and I expressed a certain discomfort with identity in both these  
cases,
especially with respect to precision decimal.

Consider:
    <xs:simpleType name="u2numbers">
      <xs:restriction base="xs:precisionDecimal">
         <xs:enumeration value="1.0"/>
         <xs:enumeration value="2.0"/>
         <xs:enumeration value="3.0"/>
         <xs:enumeration value="14.0"/>
      </xs:restriction>
    </xs:simpleType>

We accepted that "1" and "1.00" would not be valid against this  
enumeration on
the grounds that enumerations of decimals were not used in practice, so  
this
infelicity was unlikely to bite anyone.

The work-around would be to enumerate a sufficient range of precisions to  
cover
the most likely cases to turn up in practice:
    <xs:simpleType name="u2numbers">
      <xs:restriction base="xs:precisionDecimal">
         <xs:enumeration value="1"/>
         <xs:enumeration value="1.0"/>
         <xs:enumeration value="1.00"/>
         <xs:enumeration value="2"/>
         <xs:enumeration value="2.0"/>
         <xs:enumeration value="2.00"/>
         <xs:enumeration value="3"/>
         <xs:enumeration value="3.0"/>
         <xs:enumeration value="3.00"/>
         <xs:enumeration value="14"/>
         <xs:enumeration value="14.0"/>
         <xs:enumeration value="14.00"/>
      </xs:restriction>
    </xs:simpleType>
Painful in practice, impossible in the general case (although I suppose you
could enumerate to the limits of precision supported by your processor,  
urgh.)

Or you put in a pattern facet instead, which can also be painful.

Consider this definition:

<xs:element name="meterMin" type="xs:precisionDecimal"/>

Somewhere in a content model:
    <xs:element ref="meterMin" fixed="1.0"/>

In this case <meterMin>1.00</meterMin>  and <meterMin>1</meterMin>
would be rejected.

Here, however, there is no workaround that allows you the simplicity of  
using
the fixed attribute: you have to change the type. If you wanted to have
different fixed values for different uses of the element meterMin in your
schema, you have to jump through some rather painful hoops using local
definitions that have nasty enumerations or patterns in them: the type of
each use of meterMin would have to be different.

I still question the wisdom of using identity in either of these cases.  
Most
types do not distinguish identity and equality, and in those cases that  
do, the
results are unhelpful, as shown.

//Mary

Received on Friday, 3 December 2004 17:53:16 UTC