0

I use WebService, which return me data of next xml-format:

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

Where Property1, Property2 and Property3 is double. I tryed to parse this data by XmlSerializer, which expect, that decimal separator is '.' and parsing failed. I trying to realize IXmlSerializable interface by the next way:

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));

        }
    }

But in debug window I see next output:

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=;

I can not understand why? How to get 99.2 as value of Property2?

Mixim
  • 972
  • 1
  • 11
  • 37
  • 1
    Why would you? 99.2 is the value of Property2, not Property1. – J. Steen Apr 07 '15 at 13:11
  • 3
    That has been serialised incorrectly. XML doubles should always be serialised using the invariant culture, which uses a dot as a decimal mark, not a comma. – Matthew Watson Apr 07 '15 at 13:13
  • 1
    You'll need to deserialize it to a string property and convert to decimal in code. The XML standard for numeric values is to use `.` for decimal points. – D Stanley Apr 07 '15 at 13:15
  • J.Steen, yes, I made mistake. I absolutly agree, that dot is decimal mark, but Dbms_XmlGen of Oracle use comma as decimal mark. – Mixim Apr 07 '15 at 14:45

0 Answers0