0

我有两个 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);

我得到了我需要的最终合并文件,但是 '>' 的每个实例都替换为>. 我怎样才能防止这种情况发生?

4

0 回答 0