title: Linq to XML nested query
body: <p>I'm having an issue getting a LINQ query to work. I have this XML:</p>
  
  <pre><code>&lt;devices&gt; 
     &lt;device id ="2142" name="data-switch-01"&gt;
       &lt;interface id ="2148" description ="Po1"/&gt;
     &lt;/device&gt;
     &lt;device id ="2302" name="data-switch-02"&gt;
       &lt;interface id ="2354" description ="Po1"/&gt;
       &lt;interface id ="2348" description ="Gi0/44" /&gt;
     &lt;/device&gt;
   &lt;/devices&gt;
  </code></pre>
  
  <p>And this code:</p>
  
  <pre><code>var devices = from device in myXML.Descendants("device")
                select new
                {
                    ID = device.Attribute("id").Value,
                    Name = device.Attribute("name").Value,
                 };
  
  foreach (var device in devices)
  {
      Device d = new Device(Convert.ToInt32(device.ID), device.Name);
  
      var vIfs = from vIf in myXML.Descendants("device")
                    where Convert.ToInt32(vIf.Attribute("id").Value) == d.Id
                    select new
                    {
                        ID = vIf.Element("interface").Attribute("id").Value,
                        Description = vIf.Element("interface").Attribute("description").Value,
                    };
      foreach (var vIf in vIfs)
      {
          DeviceInterface di = new DeviceInterface(Convert.ToInt32(vIf.ID), vIf.Description);
          d.Interfaces.Add(di);
      }
  
      lsDevices.Add(d);
  }
  </code></pre>
  
  <p>My Device object contains a List of DeviceInterfaces which I need to populate from the XML. At the moment my code only populates the first interface, any subsequent ones are ignored and I can't understand why.</p>
  
  <p>I'd also appreciate any comments on whether or not this is the right way to do it. The nested foreach loops seem a bit messy to me</p>
  
  <p>Cheers</p>