Zannith Zannith - 2 months ago 18
C# Question

retrieve xml type string

I am using xml to linq but cannot find a way to retrieve the string "thing" in the following code:

<element type = "thing">

here is my c# code

foreach (XElement q in xdoc.Descendants("question"))
{
name = #need syntax here to retrieve the type
Console.WriteLine(name);
text = q.Element("questiontext").Element("text").Value.ToString();
if (name == "truefalse")
{
qList.Add(Question.makeType(name, text));
}
}

Answer

Something like the following should work to find all the "truefalse" type questions.

var questions = 
   from question in xDoc.Descendants("question")
   where question.Attribute("type").Equals("truefalse")
   select question;
Comments