title: LINQ to XML using joins
body: <p>I have an <a href="http://en.wikipedia.org/wiki/XML" rel="nofollow noreferrer">XML</a> file in the following format where <code>action type=0</code> is the default settings.</p>
  
  <p>Actiontype 1 and 2 are override settings. So whenever Type 1 or Type 2 settings are available in the XML they should override the default settings.</p>
  
  <p>To override the field id's of the default type=0, I am trying to do a join with the field id of override type=1, so that I can get the type=1 values and use them within my application. Howvever, the join doesn't seem to work. Is there a better way to override the default values?</p>
  
  <p>Type=0 is always available, but either Type=1 or Type=2 will be passed.</p>
  
  <p>Is there another way to do this with reflection?</p>
  
  <h3>XML</h3>
  
  <pre><code>&lt;ActionTypes&gt;
      &lt;ActionType Type="0"&gt;
          &lt;Field Id="Label1" Name="StartDate" ComparePreviousYear="False" CompareCurrentYear="True"&gt;&lt;/Field&gt;
          &lt;Field Id="Label2" Name="EndDate" ComparePreviousYear="False" CompareCurrentYear="True"&gt;&lt;/Field&gt;
          &lt;Field Id="Label3" Name="Cost" ComparePreviousYear="True" CompareCurrentYear="False"&gt;&lt;/Field&gt;
          &lt;Field Id="Label4" Name="Total" ComparePreviousYear="False" CompareCurrentYear="False"&gt;&lt;/Field&gt;
      &lt;/ActionType&gt;
      &lt;ActionType Type="1"&gt;
          &lt;Field Id="Label3" Name="Cost" ComparePreviousYear="True" CompareCurrentYear="True"&gt;&lt;/Field&gt;
      &lt;/ActionType&gt;
      &lt;ActionType Type="2"&gt;
          &lt;Field Id="Label2" Name="EndDate" ComparePreviousYear="True" CompareCurrentYear="True"&gt;&lt;/Field&gt;
      &lt;/ActionType&gt;
  &lt;/ActionTypes&gt;
  </code></pre>
  
  <h3>Code</h3>
  
  <pre><code>IEnumerable&lt;XElement&gt; defaultFields = from test in defaultElements.Elements()
                                          where test.Attribute("Type").Value == "0"
                                          select test;
  
  IEnumerable&lt;XElement&gt; overrideFields = from test in defaultElements.Elements()
                                           where test.Attribute("Type").Value == "1"
                                           select test;
  
  var overrideFields = from dflt in dftElements.Elements("Field")
                         join ovrd in ovrElements.Elements("Field") on dflt.Attributes("Id") equals ovrd.Attributes("Id")
                         select dflt,ovrd;
  </code></pre>