To deserialize empty tags like 'c' in your example:
2
I used this approach. First it removes the null or empty elements from the XML file using LINQ and then it deserialize the new document without the null or empty tags to the Foo class.
public static Foo ReadXML(string file)
{
Foo foo = null;
XDocument xdoc = XDocument.Load(file);
xdoc.Descendants().Where(e => string.IsNullOrEmpty(e.Value)).Remove();
XmlSerializer xmlSer = new XmlSerializer(typeof(Foo));
using (var reader = xdoc.Root.CreateReader())
{
foo = (Foo)xmlSer.Deserialize(reader);
reader.Close();
}
if (foo == null)
foo = new Foo();
return foo;
}
Which will give you default values on the missing properties.
foo.b = 2;
foo.c = 0; //for example, if it's an integer
I joined information from this links:
Remove empty XML tags
Use XDocument as the source for XmlSerializer.Deserialize?