title: Using Linq to parse XML data into an object in c#
body: <p>I have a fairly messy XML structure that I need to process and display to the end user. The XML structure holds information about Bars of metal and the Cuts to be made for each bar. The goal is to process this file, display to the user a list of the bars grouped by bar type. They can select a bar from this list where a gridview of some sort will display the cuts for that bar. They can then select a cut and the label information for that cut will be used to create a label with a barcode and some other information.</p>
  
  <p>The structure of the XML can be seen below:</p>
  
  <pre><code> &lt;BODY&gt;
  &lt;BAR&gt;
    &lt;BRAN&gt;ALSPEC&lt;/BRAN&gt;
    &lt;SYST&gt;Hunter 100mm Flush Glazed&lt;/SYST&gt;
    &lt;CODE&gt;AS308&lt;/CODE&gt;
    &lt;DESC&gt;Door Adaptor&lt;/DESC&gt;
    &lt;DICL&gt;NOTRE DAME GLOSS&lt;/DICL&gt;
    &lt;DOCL&gt;notre dame gloss p/coat&lt;/DOCL&gt;
    &lt;LEN&gt; 6500&lt;/LEN&gt;
    &lt;STS&gt;1&lt;/STS&gt;
    &lt;POS&gt; 0&lt;/POS&gt;
    &lt;SVL&gt; 0&lt;/SVL&gt;
    &lt;IVL&gt; 0&lt;/IVL&gt;
    &lt;VROT&gt; 0&lt;/VROT&gt;
    &lt;VU1S&gt; 0&lt;/VU1S&gt;
    &lt;VU1D&gt; 0&lt;/VU1D&gt;
    &lt;VU2S&gt; 0&lt;/VU2S&gt;
    &lt;VU2D&gt; 0&lt;/VU2D&gt;
    &lt;LENR&gt; 201.3&lt;/LENR&gt;
    &lt;H&gt; 26.5&lt;/H&gt;
    &lt;MLT&gt; 1&lt;/MLT&gt;
    &lt;SCP&gt; 0&lt;/SCP&gt;
    &lt;BRS&gt; 0&lt;/BRS&gt;
    &lt;IFS&gt; 0&lt;/IFS&gt;
    &lt;BS1L&gt; 0&lt;/BS1L&gt;
    &lt;BS1R&gt; 0&lt;/BS1R&gt;
    &lt;BS2L&gt; 0&lt;/BS2L&gt;
    &lt;BS2R&gt; 0&lt;/BS2R&gt;
    &lt;ENTH&gt; 0&lt;/ENTH&gt;
    &lt;CUT&gt;
      &lt;NUM&gt; 1&lt;/NUM&gt;
      &lt;TYPE&gt;&lt;/TYPE&gt;
      &lt;ANGL&gt; 45&lt;/ANGL&gt;
      &lt;ANGR&gt; 90&lt;/ANGR&gt;
      &lt;AB1&gt; 90&lt;/AB1&gt;
      &lt;AB2&gt; 90&lt;/AB2&gt;
      &lt;IL&gt; 2064&lt;/IL&gt;
      &lt;OL&gt; 2090.5&lt;/OL&gt;
      &lt;BCOD&gt;000000231/5/44&lt;/BCOD&gt;
      &lt;CSNA&gt;&lt;/CSNA&gt;
      &lt;CSNU&gt;&lt;/CSNU&gt;
      &lt;TINA&gt;&lt;/TINA&gt;
      &lt;DESC&gt;Jamb - Right&lt;/DESC&gt;
      &lt;STAT&gt; 1&lt;/STAT&gt;
      &lt;LBL&gt;Job# 760  Item# 5&lt;/LBL&gt;
      &lt;LBL&gt;2090.5 mm&lt;/LBL&gt;
      &lt;LBL&gt;W2-D8/T15&lt;/LBL&gt;
      &lt;LBL&gt;Jamb - Right&lt;/LBL&gt;
    &lt;/CUT&gt;
    &lt;CUT&gt;
      &lt;NUM&gt; 1&lt;/NUM&gt;
      &lt;TYPE&gt;&lt;/TYPE&gt;
      &lt;ANGL&gt; 45&lt;/ANGL&gt;
      &lt;ANGR&gt; 90&lt;/ANGR&gt;
      &lt;AB1&gt; 90&lt;/AB1&gt;
      &lt;AB2&gt; 90&lt;/AB2&gt;
      &lt;IL&gt; 2064&lt;/IL&gt;
      &lt;OL&gt; 2090.5&lt;/OL&gt;
      &lt;BCOD&gt;000000231/2/45&lt;/BCOD&gt;
      &lt;CSNA&gt;&lt;/CSNA&gt;
      &lt;CSNU&gt;&lt;/CSNU&gt;
      &lt;TINA&gt;&lt;/TINA&gt;
      &lt;DESC&gt;Jamb - Right&lt;/DESC&gt;
      &lt;STAT&gt; 1&lt;/STAT&gt;
      &lt;LBL&gt;Job# 760  Item# 2&lt;/LBL&gt;
      &lt;LBL&gt;2090.5 mm&lt;/LBL&gt;
      &lt;LBL&gt;D8/T23&lt;/LBL&gt;
      &lt;LBL&gt;Jamb - Right&lt;/LBL&gt;
    &lt;/CUT&gt;
    &lt;CUT&gt;
      &lt;NUM&gt; 1&lt;/NUM&gt;
      &lt;TYPE&gt;&lt;/TYPE&gt;
      &lt;ANGL&gt; 90&lt;/ANGL&gt;
      &lt;ANGR&gt; 45&lt;/ANGR&gt;
      &lt;AB1&gt; 90&lt;/AB1&gt;
      &lt;AB2&gt; 90&lt;/AB2&gt;
      &lt;IL&gt; 2064&lt;/IL&gt;
      &lt;OL&gt; 2090.5&lt;/OL&gt;
      &lt;BCOD&gt;000000231/1/43&lt;/BCOD&gt;
      &lt;CSNA&gt;&lt;/CSNA&gt;
      &lt;CSNU&gt;&lt;/CSNU&gt;
      &lt;TINA&gt;&lt;/TINA&gt;
      &lt;DESC&gt;Jamb - Left&lt;/DESC&gt;
      &lt;STAT&gt; 1&lt;/STAT&gt;
      &lt;LBL&gt;Job# 760  Item# 1&lt;/LBL&gt;
      &lt;LBL&gt;2090.5 mm&lt;/LBL&gt;
      &lt;LBL&gt;D8/T24&lt;/LBL&gt;
      &lt;LBL&gt;Jamb - Left&lt;/LBL&gt;
    &lt;/CUT&gt;
  &lt;/BAR&gt;
   &lt;/BODY&gt;
  </code></pre>
  
  <p>The result I am looking for is something like below i.e a tree view on the left and a datagridview on the right displaying all the cuts in the job, filtered by the tree view selection (only cuts from the selected tree view level down).</p>
  
  <p><a href="http://i.stack.imgur.com/eHYYG.png" rel="nofollow">GUI Layout</a></p>
  
  <p>To achieve this I am trying to use LINQ to XML to parse the XML file into a class i have created:</p>
  
  <pre><code>public List&lt;Bars&gt; bars = new List&lt;Bars&gt;();
  
      public class Bars
      {
          public int Bar_id { set; get; }
          public string Brand { set; get; }
          public string System { set; get; }
          public string Code { set; get; }
          public string Description { set; get; }
          public string Length { set; get; }
          public string Status { set; get; }
          public string NumBars { set; get; }
          public List&lt;Cuts&gt; Cuts { set;  get; }
      }
  
      public class Cuts
      {
          public int Cut_id { set; get; }
          public int Bar_id { set; get; }
          public string AngleL { set; get; }
          public string AngleR { set; get; }
          public string LenInn { set; get; }
          public string LenOut { set; get; }
          public string Barcode { set; get; }
          public string Description { set; get; }
          public string Status { set; get; }
          public string Label1 { set; get; }
          public string Label2 { set; get; }
          public string Label3 { set; get; }
          public string Label4 { set; get; }
      }
  </code></pre>
  
  <p>I'm actually looking for some advise on weather or not this is the correct way to handle this kind of project (LINQ to XML). Should I be using data sets or some other form or data storage.</p>
  
  <p>I am new to XML and also to relational database type stuff so any advice will be greatly appreciated. Thanks in advance!</p>
  
  <p>Will</p>