我想使用 C# 获取question
和answer
值,但在此之前我想获取我需要的 ID。我正在使用这个 XML:
<root>
<information>
<name>Tasks</name>
<date>15-05-2005</date>
</information>
<tasks>
<task>
<id>1</id>
<question>Here comes question 1</question>
<answer>Answer 1</answer>
</task>
<task>
<id>2</id>
<question>Here comes question 2</question>
<answer>Answer 2</answer>
</task>
<task>
<id>3</id>
<question>Here comes question 3</question>
<answer>Answer 3</answer>
</task>
</root>
C#代码:
XDocument tasks;
int TheIdINeed = 2;
string quest = "";
string answ = "";
在表单加载时:
tasks = XDocument.Load(leveltoload);
var status = tasks.Element("level").Element("information");
quest = tasks.Element("root").Element("tasks").Element("task").Element("question").Value; // It returns me the first task data, but I need to load data with required Id (int TheIdINeed = ...)
对不起,我的英语不好。