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
Mahesh ChandRank #1 · 393K pointsPosted May 7, 2008, 11:17 AM EDT
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.
George GeorgeRank #2,261 · 618 pointsPosted May 7, 2008, 11:44 PM EDT
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
Awadhesh Pratap6 pointsPosted May 9, 2008, 1:14 AM EDT
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 GeorgeRank #2,261 · 618 pointsPosted May 9, 2008, 1:19 AM EDT
Thanks Awadhesh,
This is what I need. :-)
regards,
George