Deserialize XML element presence to bool in C#

drogii

New Member
I'm trying to deserialize some XML from a web service into C# POCOs. I've got this working for most of the properties I need, however, I need to set a bool property based on whether an element is present or not, but can't seem to see how to do this?An example XML snippet:\[code\]<someThing test="true"> <someThingElse>1</someThingElse> <target/></someThing>\[/code\]An example C# class:\[code\][Serializable, XmlRoot("someThing")]public class Something{ [XmlAttribute("test")] public bool Test { get; set; } [XmlElement("someThingElse")] public int Else { get; set; } /// <summary> /// <c>true</c> if target element is present, /// otherwise, <c>false</c>. /// </summary> [XmlElement("target")] public bool Target { get; set; }}\[/code\]This is a very simplified example of the actual XML and object hierarchy I'm processing, but demonstrates what I'm trying to achieve.All the other questions I've read related to deserializing null/empty elements seem to involve using \[code\]Nullable<T>\[/code\], which doesn't do what I need.Does anyone have any ideas?
 
Back
Top