I want to create an XML file like the above through C# serialization, what could be the class structure for this file ? So that it would generate desired XML file after serialization.
<Subjects>
<Subject>Maths</Subject>
<Questions>
<Question>Maths question 1</Question>
<Answer>Maths answer 1</Answer>
<Marks>10</Marks>
</Questions>
<Questions>
<Question>Maths question 2</Question>
<Answer>Maths answer 2</Answer>
<Marks>5</Marks>
</Questions>
<Questions>
<Question>Maths question 3</Question>
<Answer>Maths answer 3</Answer>
<Marks>20</Marks>
</Questions>
</Subjects>
<Subjects>
<Subject>Science</Subject>
<Questions>
<Question>Science question 1</Question>
<Answer>Science answer 3</Answer>
<Marks>20</Marks>
</Questions>
<Questions>
<Question>Science question 2</Question>
<Answer>Science answer 3</Answer>
<Marks>10</Marks>
</Questions>
<Questions>
<Question>Science question 3</Question>
<Answer>Science answer 3</Answer>
<Marks>20</Marks>
</Questions>
</Subjects>
I am trying with this class structure -
public class Subjects
{
public string Subject
{
get; set;
}
public List<Questions> Questions
{
get; set;
}
}
public class Questions
{
public string Question
{
get; set;
}
public string Answer
{
get; set;
}
public string Marks
{
get; set;
}
}
but it is not generating desired XML file after serialization using XMLSerializer.