[xsd-users] xsd:decimal and fractation digits
Boris Kolpackov
boris at codesynthesis.com
Thu Jun 26 07:17:12 EDT 2008
Hi Petteri,
Tolonen, Petteri <petteri.tolonen at logica.com> writes:
> When fractation digits will be supported?
There are no immediate plans to support this feature.
> <xsd:complexType name="QuantityType">
> <xsd:sequence>
>
> <xsd:element name="Quantity">
> <xsd:simpleType>
> <xsd:restriction base="xsd:decimal">
> <xsd:totalDigits value="10" />
> <xsd:fractionDigits value="2" />
> </xsd:restriction>
> </xsd:simpleType>
> </xsd:element>
>
> <xsd:element name="QuantityUoM" type="UoMType" />
> </xsd:sequence>
> </xsd:complexType>
>
> I'll set Quantity to 213.23 and result aint what i am looking for.
>
> Result:
> <Quantity>
> <Quantity>213.22999999999999</Quantity>
> <QuantityUoM>kg</QuantityUoM>
> </Quantity>
>
> Should i try to make custom decimal type or should i make custom type
> from Quantity with decimal truncation? What if there will be more
> xsd:desimal elements with different amount of fractation digits.
I would say that unless you have many xsd:decimal-based types and all
of them have the same fractionDigits/totalDigits requirements, you
should customize the Quantity type instead of xsd:decimal.
> And does it have effect that Quantity's parent element is also Quantity?
No, customization happens on the type level (the anonymous type for the
Quantity element is automatically morphed into a named type with the same
name).
The custom/wildcard example shows how to customize parsing/serialization
code via custom types (in this case you only need to customize serialization).
If you would like to customize xsd:decimal, take a look the custom-double
example:
http://www.codesynthesis.com/~boris/tmp/custom-double.zip
It also contains code that shows how to set notation/precision, remove
trailing zeros, etc.
> An another thing, i tried to read back the generated xml and i'll get
> these errors for every element:
>
> error: Element 'Quantity' should be un-qualified
You use the default namespace (xmlns="MYOWNNAMESPACE") which means
that all elements in your vocabulary should be qualified. Try to
assign some non-empty prefix to the namespace during serialization
(so that it looks something like xmlns:mon="MYOWNNAMESPACE").
Boris
More information about the xsd-users
mailing list