title: parsing xml in c# using LINQ
body: <p>I have the following xml structure</p>
  
  <pre><code>&lt;userlist&gt;
    &lt;user Name="something"&gt;
      &lt;function name="funcname"&gt;
        &lt;picture name="pictname"&gt;
           &lt;curve name="curvename"&gt;
            &lt;name&gt;NAME&lt;/name&gt;
            ...
           &lt;/curve&gt;
        &lt;/picture&gt;
       &lt;/function&gt;
       &lt;function name="function2"&gt;
       ...
       &lt;/function&gt;
     &lt;/user&gt;
  </code></pre>
  
  <p>It goes on a bit more. I have written a function to extract of the "function" tags and place them in objects using code that simplifies to this:</p>
  
  <pre><code>from function in xmlDoc.Descendants("function")
  select new FUNCTIONOBJECT {
   do all the rest...
   }.toList&lt;FUNCTIONOBJECT&gt;();
  </code></pre>
  
  <p>I am now trying to make it so that I only filter the functions for a given user. so the name attribute of the user is given. Can anyone tell me how I can make this work with LINQ?
  My attempt was:</p>
  
  <pre><code>from user in xmlDoc.Descendants("user")
  where user.Attribute("Name").Value == givenusername
  select {
     var functions =
       from function in user.Descendants("function")
       select new FUNCTIONOBJECT {
       ... more stuff
       }.toList&lt;FUNCTIONOBJECT&gt;();
  </code></pre>
  
  <p>But this is wrong and doesnt work.
  All help is good. I am pretty new to c# and still trying to wrap my head around xml parsing with LINQ.</p>
  
  <p>EDIT:
  updated version of what I have and still doesnt work:</p>
  
  <pre><code>XDocument xmlDoc = XDocument.Load(path);
  
          var functionlist =
              (from user in xmlDoc.Descendants("user")
               where user.Attribute("Name").Value == username
               select(
               (from function in user.Descendants("function")
               select new Function
               {
                   name = function.Attribute("name").Value,
                   pictures =
                      (from picture in function.Descendants("picture")
                       select new Picture
                       {
                           name = picture.Attribute("name").Value,
                           layout = picture.Element("layout").Value,
                           curves =
                              (from curve in picture.Descendants("curve")
                               select new Curve
                               {
                                   name = curve.Attribute("name").Value,
                                   section = curve.Element("section").Value,
                                   run = curve.Element("run").Value,
                                   folder = curve.Element("folder").Value,
                                   drivingpoint = curve.Element("drivingpoint").Value,
                                   display = int.Parse(curve.Element("display").Value),
                                   points =
                                      (from point in curve.Descendants("point")
                                       select new Point
                                       {
                                           id = point.Element("id").Value != null ? point.Element("id").Value : string.Empty,
                                           direction = point.Element("direction").Value != null ? point.Element("direction").Value : string.Empty,
                                       }).ToList&lt;Point&gt;(),
                               }).ToList&lt;Curve&gt;(),
                       }).ToList&lt;Picture&gt;(),
               }).ToList&lt;Function&gt;(),
               ).toList();
      }
  </code></pre>