我有两个XML文件(*.resx文件),我想将它们合并成一个文件并去掉重复的部分,但是我无法做到。我尝试了以下方法,但都没有成功:
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<string>();
foreach (XElement node in resource1.Root.Elements())
{
if (nodeContent.Contains(node.ToString()))
resource1.Remove();
else
nodeContent.Add(node.ToString());
}
resource1.Save("C:\\FinalResources.resx");
在 remove 语句中,我收到了一个 InvalidOperationException 异常 - "The parent is missing.":
我做错了什么吗?