Xml序列化的double属性

时间:2015-04-07 13:09:41

标签: c# xml serialization deserialization

我使用WebService,它返回下一个xml格式的数据:

<CallsToAbonents>
  <Property2>99,2</Property2>
  <Property1>1,2</Property1>
  <Property3>1,2</Property3>
</CallsToAbonents>

其中Property1,Property2和Property3是双倍的。我试图通过XmlSerializer解析这些数据,期望小数分隔符是&#39;。&#39;和解析失败。 我试图通过下一个方式实现IXmlSerializable接口:

public class CallsToAbonents : IXmlSerializable
    {
        public CallsToAbonents() { }
        public String Name { get; set; }
        public double Property1 { get; set; }
        public double Property2 { get; set; }
        public double Property3 { get; set; }

        public CallsToAbonents(string Name, double Property1)
        {
            this.Name = Name;
            this.Property1 = Property1;
        }

        public System.Xml.Schema.XmlSchema GetSchema() { return null; }

        public void ReadXml(System.Xml.XmlReader Reader)
        {
            /*System.Diagnostics.Debug.WriteLine(Reader.MoveToContent());
            System.Diagnostics.Debug.WriteLine(Reader.MoveToContent());*/
            while(Reader.Read())
            {
                System.Diagnostics.Debug.WriteLine("Name={0}; Value={1};", Reader.Name, Reader.Value);
            }
        }

        public void WriteXml(System.Xml.XmlWriter writer)
        {
            writer.WriteAttributeString("Name", Name);
            CultureInfo cultureInfo = CultureInfo.CurrentCulture;
            writer.WriteElementString("Property1", this.Property1.ToString(cultureInfo));
            writer.WriteElementString("Property2", this.Property2.ToString(cultureInfo));
            writer.WriteElementString("Property3", this.Property3.ToString(cultureInfo));

        }
    }

但是在调试窗口中我看到下一个输出:

Name=Property2; Value=;
Name=; Value=99,2;
Name=Property2; Value=;
Name=Property1; Value=;
Name=; Value=1,2;
Name=Property1; Value=;
Name=Property3; Value=;
Name=; Value=1,2;
Name=Property3; Value=;
Name=CallsToAbonents; Value=;

我不明白为什么?如何获得99.2作为Property2的值?

0 个答案:

没有答案