title: I need a LINQ expression to find an XElement where the element name and attributes match an input node
body: <p>I need to replace the contents of a node in an XElement hierarchy when the element name and all the attribute names and values match an input element. (If there is no match, the new element can be added.)</p>
  
  <p>For example, if my data looks like this:</p>
  
  <pre><code>&lt;root&gt;
    &lt;thing1 a1="a" a2="b"&gt;one&lt;/thing1&gt;
    &lt;thing2 a1="a" a2="a"&gt;two&lt;/thing2&gt;
    &lt;thing2 a1="a" a3="b"&gt;three&lt;/thing2&gt;
    &lt;thing2 a1="a"&gt;four&lt;/thing2&gt;
    &lt;thing2 a1="a" a2="b"&gt;five&lt;/thing2&gt;
  &lt;root&gt;
  </code></pre>
  
  <p>I want to find the last element when I call a method with this input:</p>
  
  <pre><code>&lt;thing2 a1="a" a2="b"&gt;new value&lt;/thing2&gt;
  </code></pre>
  
  <p>The method should have no hard-coded element or attribute names - it simply matches the input to the data.</p>