Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET XmlSerializer and decimals

Tags:

c#

.net

xml

xsd

I used xsd.exe on 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 the error:

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

This only seems to happen when there's a comma used as a grouping separator (i.e 87,000). If I go through and delete the commas wherever there's an error deserialization works fine.

Is there some modification I can make o the xsd to allow for comma grouping? Or better yet a way to allow for it in my code? Trying to parse a decimal in my code with commas works fine, it's just not liking it in the xml file.

like image 959
Jizugu Avatar asked Feb 23 '23 02:02

Jizugu


1 Answers

"87,000" does not match the xs:decimal type.

There is no XSD type that permits commas.

like image 79
John Saunders Avatar answered Feb 25 '23 17:02

John Saunders