I know the topic is repetative. this is not first time I am working on XmlSerializer
, and I did not have this problem. but for this time, I have no clue what is going on.
public string comp_addr01
{
get
{
return this.comp_addr01Field;
}
set
{
this.comp_addr01Field = value;
}
}
[XmlIgnore]
public bool comp_addr01Specified { get { return true; } }
I tested comp_add01Specified is being called, though not shown in xml output.
the only way so far is worked when added XmlElement(IsNullable = true)
[XmlElement(IsNullable = true)]
public string comp_addr01
{
get
{
return this.comp_addr01Field;
}
set
{
this.comp_addr01Field = value;
}
}
but now <comp_addr01 xsi:nil="true" />
xsi:nil="true" is shown yet I don't need it to be shown. I don't know what all this mess is happening
If IsNullable is false (or omitted) then a null value for comp_addr01 will result in no element being added to the xml for that property. You can't expect the serializer to write an empty tag out in this case as there is no way of knowing when it later deserializes whether that empty tag should result in a null or not - it could just be a instance of your object with no sub properties defined.
If IsNullable is true you are then telling the serializer to create an element with xsi:nil="true" when the property is null - the xsi:nil bit tells the deserializer that this element is actually null.
XmlElementAttribute.IsNullable
"Gets or sets a value that indicates whether the XmlSerializer must serialize a member that is set to null as an empty tag with the xsi:nil attribute set to true."