How to serialize a data of type string without using StringWriter as input
- by starz26
I want to serialize a input data of type string, but do not want to use StringWriter and StringReader for for serializing/Deserializing.
The reason for this is when a escapse chars are sent as part of the Input string for serializing, it is serialized but some Spl chars are inserted in the xml(eg:"").I'm getting an XMl error while deserializing this serialized data.
void M1()
{
string str = 23 + "AC"+(char)1;
StringWriter sw = new StringWriter();
XmlSerializer serializer = new XmlSerializer(typeof(String));
serializer.Serialize(sw, str);
System.Console.WriteLine("String encoded to XML = \n{0} \n", sw.ToString());
StringReader sr = new StringReader(sw.ToString());
String s2 = (String)serializer.Deserialize(sr);
System.Console.WriteLine("String decoded from XML = \n {0}", s2);
}