Overlay/Merging XDocument

elekiaby

New Member
I've seen a few questions answered related to this, but none that completely fulfills my needs. What i am trying to do is merge two XDocument documents, but have the second overwrite the first, then merge. So in the example below, the attribute of importance is the Name attribute. In the merged document, -a unique set of SettingCollection/@Name elements should exist.-if the same Setting element exists in both documents, then doc 2's element value takes precedence.-if a SettingCollection/@Name or Setting/@Name element exists in doc 1 but not doc 2, or vice versa, the merged document should include both.I have some ideas on how to do this...but i'd like to know what would we the most efficient (in terms of lines of code), that this can be done.\[code\]Doc 1:<Document> <SettingCollection Name="SettingCollectionet1"> <Setting Name="abc" value="http://stackoverflow.com/questions/10375482/x1"/> <Setting Name="def" value="http://stackoverflow.com/questions/10375482/x2"/> </SettingCollection> <SettingCollection Name="SettingCollectionet2"> <Setting Name="abc" value="http://stackoverflow.com/questions/10375482/y1"/> <Setting Name="abc" value="http://stackoverflow.com/questions/10375482/y2"/> </SettingCollection><Document>Doc 2<Document> <SettingCollection Name="SettingCollectionet1"> <Setting Name="abc" value="http://stackoverflow.com/questions/10375482/x4"/> <Setting Name="ghi" value="http://stackoverflow.com/questions/10375482/x5"/> </SettingCollection> <SettingCollection Name="SettingCollectionet3"> <Setting Name="abc" value="http://stackoverflow.com/questions/10375482/z1"/> <Setting Name="abc" value="http://stackoverflow.com/questions/10375482/z2"/> </SettingCollection><Document>Merged Doc:<Document> <SettingCollection Name="SettingCollectionet1"> <Setting Name="abc" value="http://stackoverflow.com/questions/10375482/x4"/> <Setting Name="def" value="http://stackoverflow.com/questions/10375482/x2"/> <Setting Name="ghi" value="http://stackoverflow.com/questions/10375482/x5"/> </SettingCollection> <SettingCollection Name="SettingCollectionet2"> <Setting Name="abc" value="http://stackoverflow.com/questions/10375482/y1"/> <Setting Name="abc" value="http://stackoverflow.com/questions/10375482/y2"/> </SettingCollection> <SettingCollection Name="SettingCollectionet3"> <Setting Name="abc" value="http://stackoverflow.com/questions/10375482/z1"/> <Setting Name="abc" value="http://stackoverflow.com/questions/10375482/z2"/> </SettingCollection><Document>\[/code\]
 
Back
Top