Xml Serialization vs. "True" and "False" Xml Serialization vs. "True" and "False" xml xml

Xml Serialization vs. "True" and "False"


Based on another stack overflow question you can do:

public class MySerilizedObject{    [XmlIgnore]    public bool BadBoolField { get; set; }    [XmlElement("BadBoolField")]    public string BadBoolFieldSerialize    {        get { return this.BadBoolField ? "True" : "False"; }        set        {            if(value.Equals("True"))                this.BadBoolField = true;            else if(value.Equals("False"))                this.BadBoolField = false;            else                this.BadBoolField = XmlConvert.ToBoolean(value);        }    }}


Instead of using True or False, use 0 or 1. It will work for Boolean.


You could read that value as a string into a string field, then have a readonly bool field that had an if statement in it to return bool true or false.

For example (using c#):

public bool str2bool(string str){  if (str.Trim().ToUpper() == "TRUE")      return true;  else      return false;}

And you can use it in the template:

<xsl:if test="user:str2bool($mystr)">