title: Inserting XML Element after last specific node/element
body: <p>I want to add elements after last child in the XML. But I got an error. </p>
  
  <pre><code>&lt;XML ID="Microsoft Search Thesaurus"&gt;
    &lt;thesaurus xmlns="x-schema:tsSchema.xml"&gt;
      &lt;diacritics_sensitive&gt;0&lt;/diacritics_sensitive&gt;
      &lt;expansion&gt;
          &lt;sub&gt;Internet Explorer&lt;/sub&gt;
          &lt;sub&gt;IE&lt;/sub&gt;
          &lt;sub&gt;IE5&lt;/sub&gt;
      &lt;/expansion&gt;
      &lt;replacement&gt;
          &lt;pat&gt;NT5&lt;/pat&gt;
          &lt;pat&gt;W2K&lt;/pat&gt;
          &lt;sub&gt;Windows 2000&lt;/sub&gt;
      &lt;/replacement&gt;
      &lt;expansion&gt;
          &lt;sub&gt;run&lt;/sub&gt;
          &lt;sub&gt;jog&lt;/sub&gt;
      &lt;/expansion&gt;
      &lt;expansion&gt;
        &lt;sub&gt;home&lt;/sub&gt;
        &lt;sub&gt;house&lt;/sub&gt;
      &lt;/expansion&gt;
    &lt;/thesaurus&gt;
  &lt;/XML&gt;
  </code></pre>
  
  <p>My code is below and I encounter this error, when I debug the code. </p>
  
  <blockquote>
    <p>InvalidOperationException was unhandled.</p>
    
    <blockquote>
      <p>Sequence contains no elements.</p>
    </blockquote>
  </blockquote>
  
  <pre><code>XDocument doc = XDocument.Load("tseng.xml");  //load the xml file.
  IEnumerable&lt;XElement&gt; MemberList = doc.Element("XML").Elements("thesaurus");
  var Member = new XElement("expansion",
                   new XElement("sub", "home"),
                   new XElement("sub", "house")
               );
  MemberList.Last().AddAfterSelf(Member);  //add node to the last element.
  doc.Save("tseng.xml");
  </code></pre>
  
  <p>This error is for specific line:</p>
  
  <pre><code>MemberList.Last().AddAfterSelf(Member);
  </code></pre>
  
  <p>I don't know what is my problem on this code. How can I add element after last <code>&lt;expansion&gt;</code> node to my XML file?</p>
  
  <p>Can you help me for this problem? Thanks.</p>