I have an XML file for which i generated the XSD file using Visual Studio Schema generator. Then to generate the class i used the Xsd2Code tool, for which some designer file as well as part of this called ABC.Designer.cs.
Now i need to do the following activities using this file.
I need to Deserialize the XML file which has values in it and bind then to some controls let's say a text box. I have written the below code for the same.
using (FileStream xmlStream = new FileStream(@"C:\Desktop\abc.xml", FileMode.Open))
{
using (XmlReader xmlReader = XmlReader.Create(xmlStream))
{
XmlSerializer serializer = new XmlSerializer(typeof(ABC));
ABC deserializedStr = serializer.Deserialize(xmlReader) as ABC;
txtBox.Text = deserializedStr.Students.Student.Name.ToString();
}
}
Now the above deserializedStr has all the objects of the created xsd class. How can i iterate the values so that i can assign them to the respective controls. Also how to add data back from the textbox to the xml i.e. Serialization.
No comments:
Post a Comment