Zannith Zannith - 1 year ago 117
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
text = q.Element("questiontext").Element("text").Value.ToString();
if (name == "truefalse")
qList.Add(Question.makeType(name, text));

Answer Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download