xs:decimal and the totalDigits facet

Hi,

There's an inconsistency between some schema processors wrt xs:decimal
and the totalDigits facet. I think MSXML and Libxml2 have problems
computing the correct totalDigits for values < 0.

Scenario:

decimal.xsd
-----------
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	
	<xsd:simpleType name="myDecimal">
		<xsd:restriction base="xsd:decimal">
			<xsd:totalDigits value="6"/>			
		</xsd:restriction>
	</xsd:simpleType>

	<xsd:element name="foo">
		<xsd:complexType>
			<xsd:sequence>
				<xsd:element name="val" type="myDecimal"/>
				<xsd:element name="ref" type="myDecimal"/>
			</xsd:sequence>
		</xsd:complexType>

		<xsd:key name="myKey">
			<xsd:selector xpath="val"/>
			<xsd:field xpath="."/>
		</xsd:key>

		<xsd:keyref name="myKeyRef" refer="myKey">
			<xsd:selector xpath="ref"/>
			<xsd:field xpath="."/>
		</xsd:keyref>
	</xsd:element>

</xsd:schema>

decimal.xml
-----------
<foo
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:noNamespaceSchemaLocation="decimal.xsd">
	<val>0.000931</val>
	<ref>0.000931</ref>	
</foo>

MSXML 4.0 SP2:
p:\libxml2-lab\tests\2005-10-19\decimal.xml:5,17:
totalDigits-Einschränkungsfehler.
Das Element 'val'  hat gemäß seinem Datentyp einen ungültigen Wert.

(This means that it barks at the total digits of the instance).

Xerces-J 2.7.1:
no errors

XSV:
does not seem to handle the totalDigits facet.

Saxon 8.5.1:
validation error on line 7 column 7 of
file:/p:/libxml2-lab/tests/2005-10-19/decimal.xml:
  No referenced value found for keyRef {myKeyRef}: 0.000931

Libxml2 2.6.22:
Element 'val': [facet 'totalDigits'] The value '0.000931' has more
digits than are allowed ('6').

If we change totalDigits to "7", then MSXML and Libxml2 get happy
again.

According to [1], we have:
0.000931 = 931 × 10^-6
which satisfies the following:
|931| < 10^6 and 0 <= 6 <= 6

thus a totalDigits of "6" should cover this value and MSXML and
Libxml2 are wrong, correct?

[1] http://www.w3.org/TR/xmlschema-2/#dt-totalDigits

Regards,

Kasimier

Received on Wednesday, 19 October 2005 19:35:30 UTC