I canβt understand why this test fails.
Test:
given the following XML:
<?xml version="1.0" encoding="utf-8"?> <foo> <account> 1234567890 </account> <deptCode> ABCXYZ </deptCode> </foo>
and the following class:
class Foo { [XmlElement(ElementName = "account", DataType = "normalizedString")] string account; [XmlElement(ElementName = "deptCode", DataType = "normalizedString"] string deptCode; }
when this XML deserializer:
XmlSerializer serializer = new XmlSerializer(typeof(Foo)); Foo myFoo = (Foo) serializer.Deserialize(xmlReader);
I get the following values:
Foo.account = "\r\n 1234567890 \r\n" Foo.deptCode = "\r\n ABCXYZ \r\n"
instead of the expected
Foo.account = "1234567890" Foo.deptCode = "ABCXYZ"
How can I make the deserialization process give me the expected results? I thought DataType="normalizedString"
can do it, but it doesn't seem to work, and when I use XmlReaderSettings.IgnoreWhitespace
, it just removes the character "\ r", leaving me with "\ n 1234567890"
source share