.NET XmlSerializer and Decimals

I used xsd.exe in a remote xsd file to generate some C # class definitions. One type is defined as

<xs:element name="amount"> <xs:simpleType> <xs:restriction base="xs:decimal"> <xs:fractionDigits value="2"/> </xs:restriction> </xs:simpleType> </xs:element> 

When I try to deserialize an xml file, I get an error:

 There is an error in XML document (30, 12). ---> System.FormatException: Input string was not in a correct format. 

This only happens when the comma is used as a grouping delimiter (i.e. 87,000). If I go through and remove commas wherever error deserialization works,

Is there any modification that I can do to make xsd allow grouping of a comma? Or is it even better to allow this in my code? Trying to parse the decimal code in my code with commas works fine, it just doesn't like it in the XML file.

+4
source share
2 answers

"87,000" is not of type xs:decimal .

There is no XSD type that allows commas.

+7
source

The definition of this data type does not define any size restrictions for the numbers allowed in this data type. If your form processing is not ready to process several thousand digits (or even more), you should use a limit on the permissible upper and lower limits and the number of digits per decimal point .

+1
source

All Articles