Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to write this query for this xml data in linq to xml?
    text
    copied!<p>i've been reading through the linq to xml documentation in msdn and some other tutorials and yet i failed to find the right way to do this query as of now :(</p> <p>Basically, i want to loop through each student in the class, for each question, keep a counter of individual skill, i.e. for student 123, the tally should be 001.101.033.002.001 - 1, 001.101.035.002.001 - 1, 001.101.033.002.002 - 0. as the skills counter is based on whether the question is right(1) or wrong(0).</p> <pre><code>&lt;assessment name="english101" level="primary 6"&gt; &lt;class id="23" name="1A"&gt; &lt;student id="123" name="Jack Black"&gt; &lt;question id="101" correct="1"&gt; &lt;skill id="001.101.033.002.001" topicId="033" subtopicId="002" subtopicdesc="Launching a browser" topicdesc="Point and Click"&gt;Able to recognize and use desktop icon&lt;/skill&gt; &lt;skill id="001.101.035.002.001" topicId="035" topicDesc="Typing" subtopicId="002" subtopicDesc="Using Words"&gt;Able to write on screen&lt;/skill&gt; &lt;/question&gt; &lt;question id="102" correct="0"&gt; &lt;skill id="001.101.033.002.002" topicId="033" subtopicId="002" subtopicdesc="Launching a browser" topicdesc="Point and Click"&gt;Able to recognize and use the mouse&lt;/skill&gt; &lt;skill id="001.101.035.002.001" topicId="035" topicDesc="Typing" subtopicId="002" subtopicDesc="Using Words"&gt;Able to write on screen&lt;/skill&gt; &lt;/question&gt; &lt;/student&gt; &lt;student id="124" name="Tim Robbins"&gt; &lt;question id="103" correct="1"&gt; &lt;skill id="001.101.033.002.002" topicId="033" subtopicId="002" subtopicdesc="Launching a browser" topicdesc="Point and Click"&gt;Able to recognize and use the mouse&lt;/skill&gt; &lt;skill id="001.101.035.002.001" topicId="035" topicDesc="Typing" subtopicId="002" subtopicDesc="Using Words"&gt;Able to write on screen&lt;/skill&gt; &lt;/question&gt; &lt;dtasResult&gt; &lt;skill id="001.101.033.002.002" result="weak" /&gt; &lt;skill id="001.101.033.002.002" result="strong" /&gt; &lt;/dtasResult&gt; &lt;/student&gt; &lt;/class&gt; &lt;/assessment&gt; </code></pre> <p>so far the code i have is here:</p> <pre><code> //Open up the xml and traverse to the student nodes. XElement root = XElement.Load(fileLocation); IEnumerable&lt;XElement&gt; students = root.Elements("class").Elements("student"); string currentStudentId = ""; foreach (XElement student in students) { currentStudentId = student.Attribute("id").ToString(); //this code chunk below doesn't work! XElement questions = root.Descendants("question") .Where(question =&gt; question.Attribute("")); Console.WriteLine(student.DescendantsAndSelf("question")); Console.WriteLine(); Console.WriteLine(); } </code></pre> <p>i have yet to figure out how to do the looping for each question per student.. and the code in the middle of the foraech doesn't work!!</p> <h2>Updates:</h2> <p>if i wanted to calculate the total question per student, how would i be able to modify your query above to do so? i try grp.Count(z => z.Correct) and other method but i can't get it right thanks :)</p>
 

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