c# - Class serialization in XML -
[xmlroot("class1")] class class1 { [(xmlelement("product")] public string product{get;set;} [(xmlelement("price")] public string price{get;set;} } this class. in price contains '£' symbol. after serializing xml '?' instead of '£'.
what need '£' in xml? or how can pass data in price cdata?
your problem must how xml written file.
i've written program uses information you've given me far, , when print xml string out, correct.
i conclude error happening either when data written xml file, or when read in xml file.
using system; using system.collections.generic; using system.io; using system.xml; using system.xml.serialization; namespace consoleapplication1 { class program { static void main() { new program().run(); } void run() { class1 test = new class1(); test.product = "product"; test.price = "£100"; test(test); } void test<t>(t obj) { xmlserializernamespaces xsn = new xmlserializernamespaces(); xsn.add("", ""); xmlserializer submit = new xmlserializer(typeof(t)); stringwriter stringwriter = new stringwriter(); xmlwriter writer = xmlwriter.create(stringwriter); submit.serialize(writer, obj, xsn); var xml = stringwriter.tostring(); // xml serialization code. in obj object serialize console.writeline(xml); // £ sign fine in output. } } [xmlroot("class1")] public class class1 { [xmlelement("product")] public string product { get; set; } [xmlelement("price")] public string price { get; set; } } }
Comments
Post a Comment