Hey,
I have the problem, that I have to serialize multiple objects of the same type to a xml-file with the XmlSerializer-Class. But I'm only able to create xml-files like this one here:
<Projects>
<Name>A</Name>
<TimeTotal>0</TimeTotal>
<TimeToday>0</TimeToday>
<Comment>a</Comment>
</Projects>
<Projects>
<Name>B</Name>
<TimeTotal>0</TimeTotal>
<TimeToday>0</TimeToday>
<Comment>b</Comment>
</Projects>
But thats invalid xml. So i want that it looks like this:
<TimeProjects>
<Projects>
<Name>A</Name>
<TimeTotal>0</TimeTotal>
<TimeToday>0</TimeToday>
<Comment>a</Comment>
</Projects>
<Projects>
<Name>B</Name>
<TimeTotal>0</TimeTotal>
<TimeToday>0</TimeToday>
<Comment>b</Comment>
</Projects>
</TimeProjects>
So the problem is that I don't know how to add
ONLY ONE TIME a root element and then multiple sub-elements.
Thats my code how I try to add objects to a xml-file:
XmlSerializer xmlSerializer = new XmlSerializer(typeof(TimeProjects));
ProjectWriter = new StreamWriter(filePath, true);
TimeProjects project = new TimeProjects { Name = projectName, Comment = comments, TimeToday = timeToday, TimeTotal = timeTotal };
xmlSerializer.Serialize(ProjectWriter, project);
ProjectWriter.Close();
I hope you can help me. If you need more informations with that, just ask me please!!