【发布时间】:2013-10-02 07:39:30
【问题描述】:
我有 2 个相同类型的 XML 元素(来自具有相同架构的不同 XML 文档),如下所示:
<Parent>
<ChildType1>contentA</ChildType1>
<ChildType2>contentB</ChildType2>
<ChildType3>contentC</ChildType3>
</Parent>
<Parent>
<ChildType1>contentD</ChildType1>
<ChildType3>contentE</ChildType3>
</Parent>
元素类型 ChildType1、ChildType2 和 ChildType3 在 Parent 元素中最多可以有一个实例。
我需要做的是将第二个父节点的内容与第一个父节点合并成一个新节点,如下所示:
<Parent>
<ChildType1>contentD</ChildType1>
<ChildType2>contentB</ChildType2>
<ChildType3>contentE</ChildType3>
</Parent>
【问题讨论】:
-
您不想将第二个节点复制到第一个节点中,而是想用第二个节点覆盖第一个节点。或者你的样本结果是错误的。
-
覆盖节点意味着结果将不包含
元素。但我同意,复制也不是最好的术语。
标签: c# xml linq-to-xml xelement