I am trying to serialise the following class using xmlserializer and one of the property is bound to contain some html data.
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public partial class Data
{
private string dataWithHTMLContent;
[System.Xml.Serialization.XmlElementAttribute(Order =1)]
public string DataWithHTMLContent
{
get
{
return this.dataWithHTMLContent;
}
set
{
this.dataWithHTMLContent = value;
}
}
}
//serializes Object and saves to file system
var data= new Data();
data.DataWithHTMLContent= "Some data A & B with value <=10";
var xmlSerializer = new XmlSerializer(typeof(Data));
var sw = new StringWriter();
xmlSerializer.Serialize(sw, data);
var xmlDoc = new XmlDocument();
var xmlString = sw.ToString();
xmlDoc.LoadXml(xmlString);
xmlDoc.Save...//to save to file system for checking
When i created the xml file the contents of the DataWithHTMLContent node gets html encoded (This content is not entirely HTML in nature, it contains certain reserved characters). How can i stop the html encoding operation. Is there any particular attribute that can be applied to DataWithHTMLContent property to avoid getting html encoded.
I do not want my data to show as "Some data A & B with value <=10
"
). It's only safe to do your solution if it's XHTML. – LostInComputer May 21 '14 at 00:53