When I write:
var d = 12.34D;
d.ToString();
it gives "12,34"
, but when I serialize object with double field, it gives "12.34"
It is because XmlSerializer
uses some specific format/culture? What exactly? I've looked into Double's source code but not seen implementation of IXmlSerializable
.
Thanks.
XML serialization is the process of converting XML data from its representation in the XQuery and XPath data model, which is the hierarchical format it has in a Db2® database, to the serialized string format that it has in an application.
As with the CreatePo method, you must first construct an XmlSerializer, passing the type of class to be deserialized to the constructor. Also, a FileStream is required to read the XML document. To deserialize the objects, call the Deserialize method with the FileStream as an argument.
NET ships with two formatters: a binary formatter and a Simple Object Access Protocol (SOAP) formatter. The binary formatter generates a compact binary representation of the object's state. It's relatively fast to serialize an object into binary format and to deserialize an object from binary format.
The XmlSerializerWriter
uses XmlConvert.ToString
to convert the values.
The relevant part from that class is this:
return value.ToString("R", NumberFormatInfo.InvariantInfo);
So it uses the invariant culture, which happens to output the string that is conforming to the XML RFC (So a period as decimal separator).
Format specifier "R"
is documented here:
The round-trip ("R") format specifier attempts to ensure that a numeric value that is converted to a string is parsed back into the same numeric value. This format is supported only for the Single, Double, and BigInteger types.
It means that the other end will produce the same double
result when deserializing the string value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With