I have an XDocument that contains a number of data items.
I have another XDocument that contains a very small collection of data items. The data items in the smaller document have corresponding elements in the larger document at matching paths.
What I want to do is loop through the smaller document and for each element I find I want to update the larger document so that its corresponding value is replaced with that of the smaller document.
For example, the larger document:
<Rootelement>
<Desktop>
<A>
<El1 label="original blah" />
</A>
</Desktop>
<Desktop>
<B>
<El2 />
</B>
</Desktop>
<Desktop>
<C>
<El3 label="I'm the label" tooltip="I'm the tooltip" />
</C>
</Desktop>
</Rootelement>
The smaller document:
<Rootelement>
<Desktop>
<C>
<El3 label="The NEW Label" tooltip="The NEW Tooltip" />
</C>
</Desktop>
</Rootelement>
I want to take the element at the path Rootelement/Desktop/C/El3 and replace the element at the same path in the larger document with the one from the smaller one, so the large document becomes:
<Rootelement>
<Desktop>
<A>
<El1 label="original blah" />
</A>
</Desktop>
<Desktop>
<B>
<El2 />
</B>
</Desktop>
<Desktop>
<C>
<El3 label="The NEW Label" tooltip="The NEW Tooltip" />
</C>
</Desktop>
</Rootelement>
What is the best way for me to do this?
1 Answer