I'm not quite sure how to ask this, or if this even exists, but I have a need to merge two xelements with one taking precendence over the other, to become just one element. This is may be thought of as similar to the way Outlook 2007 merges two contacts that seem to be the same based of the contact name.
The preference here is VB.NET and Linq, but any language would be helpful if it demonstrates how to do this without me coding to manually pick apart and and resolve every single element and attribute.
For example, let's say I have two elements. Humor me on them being as different as they are.
1.
<HockeyPlayer height="6.0" hand="left">
<Position>Center</Position>
<Idol>Gordie Howe</Idol>
</HockeyPlayer>
2.
<HockeyPlayer height="5.9" startinglineup="yes">
<Idol confirmed="yes">Wayne Gretzky</Idol>
</HockeyPlayer>
The result of a merge would be
<HockeyPlayer height="6.0" hand="left" startinglineup="yes">
<Position>Center</Position>
<Idol confirmed="yes">Gordie Howe</Idol>
</HockeyPlayer>
Notice a few things: the height
attribute value of #1 overrode #2. The hand
attribute and value was simply copied over from #1 (it doesn't exist in #2). The startinglineup
attribute and value from #2 was copied over (it doesn't exist in #1). The Position
element in #1 was copied over (it doesn't exist in #2). The Idol
element value in #1 overrides #2, but #2's attribute of confirmed
(it doesn't exist in #1) is copied over.
Net net, #1 takes precendence over #2 where there is a conflict (meaning both have the same elements and/or attributes) and where there is no conflict, they both copy to the final result.
I've tried searching on this, but just can't seem to find anything, possibly because the words I'm using to search are too generic. Any thoughts or solutions (esp. for Linq)?