title: Loading XML based on attribute value
body: <p>first time poster, long time reader.
  I've got an XML import to write (another first), and i'm getting lost in the conflicting methods and approaches that can be adopted.</p>
  
  <p>The XML I'm trying to Import looks roughly  like this:</p>
  
  <pre><code>...
  &lt;TableRow&gt;
      &lt;Field Name="DeliveryNote" Type="etc.."&gt;Text&lt;/Field&gt;
      &lt;Field Name="OrderNumber" Type="etc.."&gt;Text&lt;/Field&gt;
      and so on...
  &lt;/TableRow&gt;
  ...
  </code></pre>
  
  <p>I have an object with Properties for the majority of the fields (not all required), and I'm currently populating the properties in a constructor that is thrown the relevant XElement to build from, like so:</p>
  
  <pre><code>public Order(XElement p_tableRow)
  {
  foreach (XElement field in p_TableRow.Elements("Field"))
      {
          switch (field.Attribute("Name").Value)
          {
              case "DeliveryNote":
                  ReasonCode = field.Value;
                  break;
              case "OrderNumber":
                  OrderID = field.Value;
                  break;
              case "ProductCode":
                  CustProductCode = field.Value;
                  break;
              case "Quantity":
                  QuantityCharged = field.Value;
                  break;
  ...
  </code></pre>
  
  <p>My problem is that whilst this gets the job done, it seems awfully clunky (and ugly). Surely there is a better way?</p>
  
  <p>I've tried getting my head around how to do this with projection but haven't found an example where you're deciding the destination of the data based on an attribute in the node.</p>
  
  <p>I'm using .NET 3.5</p>
  
  <p>Any pointers would be massively appreciated.</p>