I have an XML file from which I am parsing some content to display in a list:
Class:
public class SampleClass
{
public string Sample {get; set;}
public string Definite {get; set;}
public string Random {get; set;}
}
XML File Sample:
<Question>
<Sample>This is sample 1</Sample>
<Definite>Answer 1</Definite>
</Question>
<Question>
<Sample>This is sample 2</Sample>
<Definite>Answer 2</Definite>
</Question>
...
Currently, I am parsing content from the list easily and making this list.
_list = xmlDoc.Descendants("Question")
.Select(
q => new SampleClass
{
Sample = q.Element("Sample").Value,
Definite = q.Element("Definite").Value
})
.ToList();
However, in the list I want to include another element that is to be parsed from the XML file in a random order eg:
SampleClass list Sample Definite Random
^ ^ ^
List element 1: This is sample 1, Answer 1, Answer5
List element 2: This is sample 2, Answer 2, Answer1
List element 3: This is sample 3, Answer 3, Answer4 ...
I wanted to ask how do I include this Random
element in the list while parsing such that q.Random
is assigned a random <Definite> Value </Definite>
from the Question
nodes?
Duplicates of random in the list are not acceptable.