I’m trying to serialize a xml file into a class where a element can be empty
XML file
<Status StatusId="1">
<StatusName>Not inspected</StatusName>
<Acute></Acute>
</Status>
<Status StatusId="2">
<StatusName>Acute</StatusName>
<Acute>1</Acute>
</Status>
The class
private int _acute;
public int Acute
{
get { return _acute; }
set
{
_acute = value;
NotifyPropertyChanged("Acute");
}
}
I have tried int? and [XmlElement( IsNullable = true )] but nothing works anyone know how to read in empty elemet without getting any errors.
Try making Acute an
int?. Ints can’t contain null, nullable ints (int?s) can.EDIT: Note to self – read everything before responding.
Perhaps your problem is that
<Acute>isn’t actually missing from the XML, it’s there but with an empty value, which doesn’t translate to any int? Try removing the<Acute></Acute>line from the XML, and change the property back to int? .