我想通过C#序列化创建一个类似上面的XML文件,这个文件的类结构是什么?这样它会在序列化后生成所需的XML文件。
<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>
我正在尝试使用这个类结构 -
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;
}
}
但是在使用序列化后它没有生成所需的XML文件 XMLSerializer的。