Sorry, I realised this just after I posted it.

Yes, it's definately a bug - you can see it happening in the VS.Net XML
designer (see below).


The problem is that XmlConvert uses the following code:
        public static string ToString(Decimal value)  {
            return value.ToString(null, NumberFormatInfo.InvariantInfo);
        }
to generate the XSD-compatible serialized decimal format. It should not be
relying on InvariantInfo to serialize the Decimal

To see the bug appearing in VS.Net:

Source.xml
----------

<xml xmlns="http://tempuri.org/source.xsd";
xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
        <a>0</a>
        <a>0</a>
</xml>


Source.xsd
----------

<xs:schema id="xml" targetNamespace="http://tempuri.org/source.xsd";
xmlns:mstns="http://tempuri.org/source.xsd";
xmlns="http://tempuri.org/source.xsd";
xmlns:xs="http://www.w3.org/2001/XMLSchema";
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
attributeFormDefault="qualified" elementFormDefault="qualified">
        <xs:element name="xml" msdata:IsDataSet="true" msdata:Locale="en-GB"
msdata:EnforceConstraints="False">
                <xs:complexType>
                        <xs:choice maxOccurs="unbounded">
                                <xs:element name="a" nillable="true">
                                        <xs:complexType>
                                                <xs:simpleContent 
msdata:ColumnName="a_Text" msdata:Ordinal="0">
                                                        <xs:extension 
base="xs:decimal"></xs:extension>
                                                </xs:simpleContent>
                                        </xs:complexType>
                                </xs:element>
                        </xs:choice>
                </xs:complexType>
        </xs:element>
</xs:schema>



Steps to Reproduce
------------------

Open source.xml in the Data view of the Xml Designer
Change one of the rows to read 0.00005.
Move focus away from that cell - It should change to 5E-05
Change to the Xml view of the Xml Designer - The decimal value has been
serialized wrongly
Change to the Data view of the Xml Designer - The designer shows it is
unable to read the invalid value by displaying "(null)".

ps If anyone wants to fix this in the ROTOR codebase, the tabular comment at
line 374 also wants updating with an x instead of a o for the Decimal to
String mapping.


Richard

> -----Original Message-----
> From: dotnet discussion [mailto:[EMAIL PROTECTED]]On Behalf Of
> Morten Abrahamsen
> Sent: 31 May 2002 12:01
> To: [EMAIL PROTECTED]
> Subject: Re: [DOTNET] XmlConvert and Decimal bug
>
>
> I know!
>
> But the problem isn't the parser, it's the XmlSchema 'compliant'
> XmlConvert.ToString(decimal) function.
> I thought the whole point of the XmlConvert class was to provide
> XmlSchema compliant conversion functions.
>
> And as such, the XmlConvert.ToString(decimal) shouldn't write the
> exponential format in the first place...
>
> Am I wrong ?
>
> Morty
>
> -----Original Message-----
> From: Richard Birkby [mailto:[EMAIL PROTECTED]]
> Sent: Friday, May 31, 2002 12:47 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [DOTNET] XmlConvert and Decimal bug
>
>
> The conversion calls
>
>         dec=Decimal.Parse("5E-05", NumberStyles.AllowLeadingSign|
>
> NumberStyles.AllowDecimalPoint|
>
> NumberStyles.AllowLeadingWhite|
>
> NumberStyles.AllowTrailingWhite,
>
> NumberFormatInfo.InvariantInfo);
>
> which calls into native code via the Number class. It specifically
> disallows the NumberStyles.AllowExponent bitfield because the XML Schema
> datatypes spec does not allow exponents for Decimal types.
>
> http://www.w3.org/TR/xmlschema-2/#decimal
>
> The spec allows up to 18 digits and no exponent.
>
>
> Richard
>
> > -----Original Message-----
> > From: dotnet discussion [mailto:[EMAIL PROTECTED]]On Behalf
> > Of Morten Abrahamsen
> > Sent: 31 May 2002 11:16
> > To: [EMAIL PROTECTED]
> > Subject: [DOTNET] XmlConvert and Decimal bug
> >
> >
> > One would assume that the following would work:
> >
> >         string decimalString = XmlConvert.ToString(0.00005M);
> >         decimal dec = XmlConvert.ToDecimal(decimalString);
> >
> > However it throws a FormatException because the string conversion
> > results in an exponential format, which isn't permitted in the
> > ToDecimal parser.
> >
> > Is this a common bug, or is this related to some strange locale
> > settings... (it should be schema compliant and locale invariant
> > though..)
> >
> > Any thoughts ?
> >
> > Morty
> >
> > You can read messages from the DOTNET archive, unsubscribe from
> > DOTNET, or subscribe to other DevelopMentor lists at
> > http://discuss.develop.com.
>
> You can read messages from the DOTNET archive, unsubscribe from DOTNET,
> or subscribe to other DevelopMentor lists at http://discuss.develop.com.
>
> You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
> subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to