C# Get XML Node Value
I want to get the question and answer values using C#, but before that I
want to get the ID I need. I'm using this 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# code:
XDocument tasks;
int TheIdINeed = 2;
string quest = "";
string answ = "";
On form load:
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 = ...)
I'm sorry, my English isn't good.
No comments:
Post a Comment