Storing and retrieving data from an XML file

LutttunkUnigh

New Member
I storage a set of user provided data in a file. When I took over the project, everything was saved to a plain text file. I redesigned it and now, the storage is an XML file. When the process starts, I read the XML file using XDocument and XElement classes. When I've obtained the values I put them in a constructor of my executing object.I wonder if there's a way to automagically read in the XML data so that it, sort of, transforms (or is converted to) an instance of my object.So, instead of:\[code\]XElement fromFile = XElement.Load(pathName);XElement newStuff = new XElement("MainNode", new XElement("SubNode1", myObject.valueOfSubNode1), new XElement("SubNode2", myObject.valueOfSubNode2));fromFile.ReplaceAll(newStuff);XmlTextWriter writer = ...;fromFile.Save(writer);\[/code\]I'd like to "store" the instance of myObject itself. I'm assuming that's possible. I have no idea how or even where to start.
 
Back
Top