score:1
Accepted answer
public class question
{
public int id { get; set; }
public string questiontext { get; set; }
public list<answer> answerlist { get; set; }
}
public class answer
{
public string text { get; set; }
public bool iscorrect { get; set; }
}
var results = (from x in doc.descendants("mchoice")
select new question()
{
id = convert.toint16(x.element("id")),
questiontext = x.element("question").value,
answerlist = (x.elements("answer").select(m => new answer
{
text = m.value,
iscorrect = m.attribute("correct") != null && m.attribute("correct").value == "yes"
}).tolist())
}).tolist();
score:1
public class answer
{
public string answertext { get; set; }
public bool iscorrect { get; set; }
}
Source: stackoverflow.com
Related Query
- Convert xml to CLR type using Linq
- Parse xml to CLR type using Linq
- How to Convert Anonymous Type to List <dynamic> using Linq to SQL in C#
- Convert xml to custom class using lambda linq
- how to convert Database Hierarchical Data to XML using ASP.net 3.5 and LINQ
- c# linq to xml error: cannot implicitly convert type
- Why did I get an exception "Cannot implicitly convert type 'bool' to 'long?'" when using the LINQ Sum method and how to fix it?
- Convert delimited string to xml in C# using LINQ
- Convert Anonymous Type to List <T> using Linq to SQL in C#
- Convert xml to class using Linq
- Convert datetime from xml to c# object using linq
- I am using LINQ to connect to a database and i get a list of properties and I want to convert it to an XML File
- Convert nested type in C# using delegates / LINQ
- convert type of collection using linq and c#
- Accessing the element type in XML using LINQ to XML
- How to convert the return type of the model data from Product entity to ProductViewModel objects using LINQ select?
- Convert all T values using LINQ and assign them to an array of different type
- error Cannot implicitly convert type when Join Merged Data Table using Linq
- Convert flat XML to hierarchical structure using LINQ
- Project a Type to class object by filtering out attributes using linq to xml
- Convert string[] to int[] in one line of code using LINQ
- Convert list to dictionary using linq and not worrying about duplicates
- How can I filter a dictionary using LINQ and return it to a dictionary from the same type
- Convert string to int array using LINQ
- Using LINQ to convert List<U> to List<T>
- Convert dictionary values to list using linq
- How do I convert from a Dictionary to a SortedDictionary using LINQ in C#?
- Using LINQ to convert a list to a CSV string
- Empty namespace using Linq Xml
- Create a list of one object type from a list of another using Linq
More Query from same tag
- How to make LEFT JOIN in Lambda LINQ expressions
- Select which property to use based on the value passed into the method
- Problem in implementing order by logic for multiple condition to order the final results
- LinqDataSource: How to assign IQueryable value to where parameters in code
- Join and Group in LINQ
- Get items from nested list
- Why Does IQueryable Select Has Invalid Arguments With DTO but works with object?
- C# Determing whether any element in a string array contains a given string anywhere
- LINQ join multiple tables on same column
- string replace using Linq in c#
- Update multiple rows in iQueryable
- Prevent ODP.net from nationalizing string
- Group by multiple tables and still have access to the original query?
- mongodb linq provider: incorrect behavior for fields of type decimal?
- aggregate list with linq with sum
- LINQ EF copy and paste a record with a difference field
- Is it possible for a post method to return a confirm box to the user before continuing on with the method?
- Linq result as collection of parent (User) object
- Update enquiries for C#
- The nested query is not supported. Operation1='UnionAll' Operation2='MultiStreamNest'
- Finding and printing a value from 2 different lists using LINQ
- How to fetch unique objects using Linq
- Entity Framework/Linq EXpression converting from string to int
- I need to set an attribute in my object with a value of a procedure. How i do this?
- how to write the following in LINQ syntax
- How do I aggregate joins?
- Joins Based on Lambda Expressions
- How can I populate a list of objects from another list using LINQ?
- Help with Linq and dynamic object property in select
- Fetching 1 record based on the name of the logged in User and show these values in txt boxes (c#)