Note that there are some explanatory texts on larger screens.

plurals
  1. POAssign to class property from XML randomly
    primarykey
    data
    text
    <p>I have an XML file from which I am parsing some content to display in a list:</p> <h3>Class:</h3> <pre class="lang-c prettyprint-override"><code>public class SampleClass { public string Sample {get; set;} public string Definite {get; set;} public string Random {get; set;} } </code></pre> <h3>XML File Sample:</h3> <pre class="lang-xml prettyprint-override"><code>&lt;Question&gt; &lt;Sample&gt;This is sample 1&lt;/Sample&gt; &lt;Definite&gt;Answer 1&lt;/Definite&gt; &lt;/Question&gt; &lt;Question&gt; &lt;Sample&gt;This is sample 2&lt;/Sample&gt; &lt;Definite&gt;Answer 2&lt;/Definite&gt; &lt;/Question&gt; ... </code></pre> <p>Currently, I am parsing content from the list easily and making this list.</p> <pre class="lang-c prettyprint-override"><code>_list = xmlDoc.Descendants("Question") .Select( q =&gt; new SampleClass { Sample = q.Element("Sample").Value, Definite = q.Element("Definite").Value }) .ToList(); </code></pre> <p>However, in the list I want to include another element that is to be parsed from the XML file in a random order eg:</p> <pre><code>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 ... </code></pre> <p>I wanted to ask how do I include this <code>Random</code> element in the list while parsing such that <code>q.Random</code> is assigned a random <code>&lt;Definite&gt; Value &lt;/Definite&gt;</code> from the <code>Question</code> nodes?</p> <p>Duplicates of random in the list are not acceptable.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload