Not quite ... it is not invalid XML, but the content of that XML cannot be
mapped to the .NET type system.
The XML snippet says that the value of ProcessingStartedOn should be null.
ValueTypes in the .NET framework, such as the DateTime type, cannot be null
and you mentioned that you are trying to deserialize the ProcessingStartedOn
element to a field of type DateTime.
With reference types you can tell the XmlSerializer to handle the the
xsi:nil="true" attribute correctly, by setting the IsNullable property of
the XmlElement attribute to true, but again, this doesn't work for value
types.
If absolutely have to be able to parse this XML, maybe because you're not in
control of the XML document generation, then you need to somehow work around
this limitation. The easiest way would be to read the ProcessingStartedOn
element into a string property instead of a DateTime field directly. Since
string is a reference type you will be able to specify the IsNullable
property. The property set can then internally set a flag when the element
wasn't null and contained a valid date and set the value to a real DateTime
field. The code could look something like this:
public class foo
{
[XmlIgnore]
public DateTime ProcessingStartedOn;
[XmlIgnore]
public DateTime StartTimeSet = false;
[XmlElement("ProcessingStartedOn")]
public string ProcessingStartedOnString
{
get { return ProcessingStartedOn.ToString(); } // or whatever
ToXXXString you need
set { if( null != value )
{
ProcessingStartedOn = DateTime.Parse( value );
StartTimeSet = true;
}
}
}
}
--
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor
[quoted text, click to view] "Reggie Burnett" <reggie.burnett@aspect.com> wrote in message
news:eF2ZhxSrDHA.2808@TK2MSFTNGP10.phx.gbl...
> > As far as
> >
> > <ProcessingStartedOn xsi:nil=\"true\"/>
> >
> > goes: You said that ProcessingStartedOn is of type DateTime, which is a
> > ValueType and therefore can't by nullable. It can, however, be optional
if
> > that helps you out.
>
> ok, so you are saying that xsi:nil="true" is saying that the value is
null.
> So what I hear you saying is that is invalid xml.
> I would need to read this into a string and then "detect" the xsi:nil
stuff
> manually?
>
>
> Reggie
>
>