Hello All,
I feel this is a basic question. Please help me to resolve this. I am new to C# development.
I tried to create an xml out of the student object which has a list of mark objects as a member.
public class student
{
public String Name { get; set; }
public String Class { get; set; }
public List MarkList { get; set; }
}
public class Mark
{
string Subject { get; set; }
int Score { get; set; }
public Mark(string sub, int score)
{
Subject = sub;
Score = score;
}
public Mark()
{
}
}
----------------------------
private void savefile(object sender, RoutedEventArgs e)
{
List markList = new List();
markList.Add(new Mark("Physics",22));
markList.Add(new Mark("Chemistry", 23));
markList.Add(new Mark("Biology", 24));
markList.Add(new Mark("Maths", 25));
student s1 = new student();
s1.Name = "Bob";
s1.Class = "p1";
s1.MarkList =markList;
Serialise(s1);
}
static public void Serialise(student details)
{
XmlSerializer serializer = new XmlSerializer(typeof(student));
using (TextWriter writer = new StreamWriter(@"C:\Xml.xml"))
{
serializer.Serialize(writer, details);
}
}
On serializing , I am getting the output as follows.
Please help..
Thanks in advance.
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Guest UserPosted May 19, 2015, 3:06 AM
Yoko YokoPosted May 19, 2015, 3:11 AM