Hello everyone,
I want to convert an object instance to XML string, and later read the XML string to construct the object again. Any samples?
(I find some serialization samples, but all about binary format, I prefer to use XML format.)
thanks in advance,
George
George GeorgePosted May 9, 2008, 5:19 AM
Thanks Awadhesh,
This is what I need. :-)
regards,
George
Awadhesh PratapPosted May 9, 2008, 5:14 AM
You can serialize an object to xml using XmlSerializer class
System.Xml.Serialization.XmlSerializer xS = new System.Xml.Serialization.XmlSerializer(myObj.GetType()); // myObj is your object :)
xS.Serialize(Console.Out, myObj);
George GeorgePosted May 8, 2008, 3:44 AM
Sorry, my English is not very good. I do not have any database objects, like DataSet. I mean general C# object -- class instance. Any ideas?
regards,
George
Mahesh ChandPosted May 7, 2008, 3:17 PM
Do you have a class object with members or talking about any object?
In general, a DataSet is an object and you can read an XML in a DataSet using ReadXml method and write DataSet to XML doc by using DataSet.WriteXml method.