Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
998 views
in Technique[技术] by (71.8m points)

c# - XmlSerializer: The string '' is not a valid AllXsd value

I'm getting this message,"The string '7/22/2006 12:00:00 AM' is not a valid AllXsd value.", when deserializing an XML, the element contains a date, this is the property that is supposed to be mapped to the element:

[XmlElement("FEC_INICIO_REL",typeof(DateTime))]
public DateTime? FechaInicioRelacion { get; set; }

Am I doing something wrong?

UPDATE: Here is the XML:

<Detalle>
  <NOM_ASOC>Financiera Paname?a</NOM_ASOC>
  <DESCR_CORTA_RELA>PREST. PERSONAL</DESCR_CORTA_RELA>
  <FEC_INICIO_REL>7/22/2006 12:00:00 AM</FEC_INICIO_REL>
  <FEC_FIN_REL>9/22/2008 12:00:00 AM</FEC_FIN_REL>
  <MONTO_ORIGINAL>1160.0000</MONTO_ORIGINAL>
  <NUM_PAGOS>2</NUM_PAGOS>
  <DESCR_FORMA_PAGO>PAGOS VOLUNTARIOS</DESCR_FORMA_PAGO>
  <IMPORTE_PAGO>59.9400</IMPORTE_PAGO>
  <FEC_ULTIMO_PAGO>11/15/2006 12:00:00 AM</FEC_ULTIMO_PAGO>
  <MONTO_ULTIMO_PAGO>0.0000</MONTO_ULTIMO_PAGO>
  <DESCR_OBS_CORTA />
  <SALDO_ACTUAL>1078.3900</SALDO_ACTUAL>
  <NUM_DIAS_ATRASO>0</NUM_DIAS_ATRASO>
  <HISTORIA>1</HISTORIA>
  <MONTO_CODIFICADO />
  <FEC_ACTUALIZACION>10/17/2008 12:00:00 AM</FEC_ACTUALIZACION>
  <COD_GRUPO_ECON>  </COD_GRUPO_ECON>
  <TIPO_ASOC>  </TIPO_ASOC>
  <NUM_REFER>2008628116</NUM_REFER>
</Detalle>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I solved the issue by storing the date in string and then creating a getter which parses the date and returns it as DateTime.

Sample code:

    [XmlElement("Valid")]
    public string _Valid
    {
        get;
        set;
    }

    [XmlIgnore]
    public bool? Valid
    {
        get
        {
            if (!string.IsNullOrWhiteSpace(_Valid))
            {
                return bool.Parse(_Valid);
            }

            return null;
        }
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...