title: How do I merge two XDocuments removing duplicates
body: <p>I have two XML files (*.resx files) that I am trying to merge in to one removing duplicates, but am unable to do so. I've tried the following without any success:</p>
  
  <pre><code>            var resource1 = XDocument.Load("C:\\Resources.resx");
  
              var resource2 = XDocument.Load("C:\\Resources2.resx");
  
             // This results in a file with all the nodes from the second file included inside 
            // the root element of the first file to form a properly formatted, concatenated file.
              resource1.Descendants().FirstOrDefault().Add(resource2.Descendants().FirstOrDefault().Nodes());
  
              var nodeContent = new List&lt;string&gt;();               
  
              foreach (XElement node in resource1.Root.Elements())
              {                    
  
                  if (nodeContent.Contains(node.ToString()))
                      resource1.Remove();
                  else
                      nodeContent.Add(node.ToString());
              }
  
              resource1.Save("C:\\FinalResources.resx");
  </code></pre>
  
  <p>On the remove statement I get an InvalidOperationException - "The parent is missing.": </p>
  
  <p>Am I doing something wrong?</p>