Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xml Serialization vs. "True" and "False"

Tags:

I'm having an issue with deserializing an XML file with boolean values. The source XML files I'm deserializing were created from a VB6 app, where all boolean values are capitalized (True, False). When I try to deserialize the XML, I'm getting a

System.FormatException: The string 'False' is not a valid Boolean value.

Is there a way to say ignore case with an attribute?

like image 376
shannon.stewart Avatar asked Jul 20 '09 18:07

shannon.stewart


People also ask

What is serialization in XML?

XML serialization is the process of converting XML data from its representation in the XQuery and XPath data model, which is the hierarchical format it has in a Db2® database, to the serialized string format that it has in an application.

Is XML a serialization format?

XML. XML is a human-readable serialization protocol. A well known XML-like format is HTML which is used to determine the structure of web pages.

What is the basic difference between SOAP serialization and XML serialization?

XML serialization can also be used to serialize objects into XML streams that conform to the SOAP specification. SOAP is a protocol based on XML, designed specifically to transport procedure calls using XML. To serialize or deserialize objects, use the XmlSerializer class.

What is serializing and deserializing XML?

Serialization is a process by which an object's state is transformed in some serial data format, such as XML or binary format. Deserialization, on the other hand, is used to convert the byte of data, such as XML or binary data, to object type.


1 Answers

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);
        }
    }
}
like image 191
jeoffman Avatar answered Sep 29 '22 07:09

jeoffman