title: how to loop through xml nodes using XPathSelectElements or linq to xml
body: <p>I would like to loop through the nodes in the xml below and get the values of the following elements: H_Domain, H_Environment, H_Mastered. XPathSelectElements returns an IEnumerable list and indexing cannot be applied to these XElement. Anyone has got any idea how to get values for each element as shown (relative) in the code example?</p>
  
  <pre><code>private static void GetHabitation()
      {
          try
          {
              IEnumerable&lt;XElement&gt; list = xdoc.XPathSelectElements("//Audit/agents/agent/questions/H0/*");
              foreach (XElement element in list)
              {
                  Console.WriteLine(element["H_Domain"].Value);
                  Console.WriteLine(element["H_Environment"].Value);
                  Console.WriteLine(element["H_Mastered"].Value);
               }
  
              return haList;
  
          }
          catch (Exception)
          {
  
              throw;
          }
      }
  </code></pre>
  
  <p>xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Audit&gt;
     &lt;agents xmlns=""&gt;
      &lt;agent&gt;
        &lt;questions&gt;
          &lt;H0&gt;
            &lt;H_Domain&gt;RAC Raccordement Basse Tension&lt;/H_Domain&gt;
            &lt;H_Environment&gt;CPT travaux comptage&lt;/H_Environment&gt;
            &lt;H_Mastered&gt;0&lt;/H_Mastered&gt;
          &lt;/H0&gt;
          &lt;H0&gt;
            &lt;H_Domain&gt;IBT Intervention r�seau Basse Tension&lt;/H_Domain&gt;
            &lt;H_Environment&gt;TIA Travaux aux installations a�riennes&lt;/H_Environment&gt;
            &lt;H_Mastered&gt;0&lt;/H_Mastered&gt;
          &lt;/H0&gt;
          &lt;H0&gt;
            &lt;H_Domain&gt;IBT Intervention r�seau Basse Tension&lt;/H_Domain&gt;
            &lt;H_Environment&gt;AEM Actes d'exploitation et man�uvre&lt;/H_Environment&gt;
            &lt;H_Mastered&gt;0&lt;/H_Mastered&gt;
          &lt;/H0&gt;
        &lt;/questions&gt;
      &lt;/agent&gt;
    &lt;/agents&gt;
  &lt;/Audit&gt;
  </code></pre>