title: c# foreach loop though a XmlNodeList sub nodes
body: <p>I have this XML file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;message&gt;
    &lt;success/&gt;
    &lt;bookings&gt;
      &lt;booking&gt;
        &lt;rooms&gt;
          &lt;room roomCode ="101" uniqueId="abc"&gt;
            &lt;stays&gt;
              &lt;stay usedfrom="9:30" usedto="10:30" quantity="1" Price="62.5" rateCode="1"/&gt;
            &lt;/stays&gt;
            &lt;extras&gt;
              &lt;extra from="9:30" to="10:30" unitPrice="5.5" extraCode="coffee" quantity="1" inclusive="0"/&gt;
            &lt;/extras&gt;
            &lt;guests&gt;
              &lt;guest firstName="John" lastName="Doe" title="MR" ageRange="0"/&gt;
            &lt;/guests&gt;
          &lt;/room&gt;
          &lt;room roomCode ="Brd" uniqueId="xyz"&gt;
            &lt;stays&gt;
              &lt;stay usedfrom="13:30" usedto="15:30" quantity="1" unitPrice="60.0000" rateCode="RACK"/&gt;
            &lt;/stays&gt;
            &lt;guests&gt;
              &lt;guest firstName="Jean" lastName="Doe" title="MRS" ageRange="0"/&gt;
            &lt;/guests&gt;
          &lt;/room&gt;
        &lt;/rooms&gt;
      &lt;/booking&gt;
    &lt;/bookings&gt;
  &lt;/message&gt;
  </code></pre>
  
  <p>and I'm trying to get the  node, and the loop though all the  (NO s) nodes underneath (and there sub nodes).
  I've kinda done this, but it list all the  attributes each loop.</p>
  
  <pre><code>foreach (XmlNode Roomnode in RoomS)
  {
      XmlNodeList Room = doc.GetElementsByTagName("room");
      var RoomCount = Room.Count;
      Console.WriteLine("This Booking contains " + RoomCount + " room(s)");
  
      foreach (XmlNode rmxn in Room)
      {
          RoomCode = rmxn.Attributes["roomCode"].Value;
          UniqueId = rmxn.Attributes["uniqueId"].Value;
          Console.WriteLine("         Room Type: " + RoomCode);
          Console.WriteLine("         Room id: " + UniqueId);
  
          XmlNodeList Stay = doc.GetElementsByTagName("stay");
  
          foreach (XmlNode syxn in Stay)
          {
              RateCode = syxn.Attributes["rateCode"].Value;
              Quantity = syxn.Attributes["quantity"].Value;
              UnitPrice = Math.Round(Convert.ToDecimal(syxn.Attributes["unitPrice"].Value), 2);
              FromTime = syxn.Attributes["usedfrom"].Value;
              ToTime = syxn.Attributes["usedto"].Value;
              Console.WriteLine("      Staying from " + FromTime + " to " + ToTime);
              Console.WriteLine("      Price Per Day : " + Currency + UnitPrice);
              Console.WriteLine("      Using Rate Code: " + RateCode);
          }
      }
  }
  </code></pre>
  
  <p>I'm (99.99%) sure that its because of the line</p>
  
  <pre><code>XmlNodeList Stay = doc.GetElementsByTagName("stay");
  </code></pre>
  
  <p>Now, in JQUERY, I would have replaced "doc" with "this"(instead of getting the whole list again, but "this" doesn't work ("static property" message from VS).
  Can someone please tell  me what I need to do to change it from this:</p>
  
  <pre><code>     Room Type: 101
       Room id: abc
    Staying from 9:30 to 10:30
    Price Per Day : 62.5
    Using Rate Code: 1
    Staying from 13:20 to 15:30
    Price Per Day : 60.00
    Using Rate Code: RACK
       Room Type: Brd
       Room id: xyz
     Staying from 9:30 to 10:30
    Price Per Day : 62.5
    Using Rate Code: 1
    Staying from 13:20 to 15:30
    Price Per Day : 60.00
    Using Rate Code: RACK
  </code></pre>
  
  <p>to this</p>
  
  <pre><code>     Room Type: 101
       Room id: abc
    Staying from 9:30 to 10:30
    Price Per Day : 62.5
    Using Rate Code: 1
       Room Type: Brd
       Room id: xyz
    Staying from 13:20 to 15:30
    Price Per Day : 60.00
    Using Rate Code: RACK
  </code></pre>
  
  <p>Thanks</p>