我有两个XML文件,我使用以下递归片段合并在一起
var resource1 = XDocument.Load(baseFile, LoadOptions.PreserveWhitespace);
var resource2 = XDocument.Load(targetFile, LoadOptions.PreserveWhitespace);
// Merge per-element content from secondResource into firstResource
foreach (XElement childB in secondResource.Elements())
{
// Merge childB with first equivalent childA
// equivalent childB1, childB2,.. will be combined
bool isMatchFound = false;
foreach (XElement childA in firstResource.Elements())
{
if (AreEquivalent(childA, childB))
{
// Recursive merge
MergeElements(childA, childB);
isMatchFound = true;
break;
}
}
// if there is no equivalent childA, add childB into parentA
if (!isMatchFound) firstResource.Add(childB);
}
resource1.Save(outputFile);
我得到了一个像我需要的最终合并文件,但每个'>'的实例被替换为>
。我怎样才能防止这种情况发生?