How to serialize a data of type string without using StringWriter as input

Posted by starz26 on Stack Overflow See other posts from Stack Overflow or by starz26
Published on 2010-05-24T10:40:12Z Indexed on 2010/05/24 11:31 UTC
Read the original article Hit count: 207

Filed under:
|

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); }

© Stack Overflow or respective owner

Related posts about .NET

Related posts about xml-serialization