User-271186128 posted
Hi jagadishnpy,
Welcome to asp.net forum.
As for this issue, I suggest you could check the object class. When you set the property, you need to check whether it is null. You could refer to the following code:
[XmlRoot("root")]
public class Sample1Xml
{
[XmlElement("node")]
public NodeType Node { get; set; }
#region Nested type: NodeType
public class NodeType
{
[XmlAttribute("attr1")]
public string Attr1 { get; set; }
[XmlAttribute("attr2")]
public string Attr2 { get; set; }
[XmlIgnore]
public string Content { get; set; }
[XmlText]
public XmlNode[] CDataContent
{
get
{
var dummy = new XmlDocument();
return new XmlNode[] {dummy.CreateCDataSection(Content)};
}
set
{
if (value == null)
{
Content = null;
return;
}
if (value.Length != 1)
{
throw new InvalidOperationException(
String.Format(
"Invalid array length {0}", value.Length));
}
var node0 = value[0];
var cdata = node0 as XmlCDataSection;
if (cdata == null)
{
throw new InvalidOperationException(
String.Format(
"Invalid node type {0}", node0.NodeType));
}
Content = cdata.Data;
}
}
}
#endregion
}
For more details, please refer to the following links:
https://social.msdn.microsoft.com/Forums/en-US/6f59a2c0-2f70-4f19-9210-c675bbdce48d/cdata-serialization-with-xmlserializer?forum=asmxandxml
http://stackoverflow.com/questions/9673030/deserialize-xml-with-empty-elements
http://www.codeproject.com/Articles/483055/XML-Serialization-and-Deserialization-Part
Best regards,
Dillion