I’m trying to merge two XML documents. The first one is a kind of template with default values, and the second one has the same structure with missing fields.
I would like to load both files and fill missing fields of the second XML file with default values given in the first file.
For example :
DefaultConfig.xml :
<CollectionItem>
<Item>
<var1>10</var1>
<var2>20</var2>
</Item>
</CollectionItem>
Config1.xml :
<CollectionItem>
<Item>
<var1>5</var1>
</Item>
<Item>
<var2>5</var2>
</Item>
</CollectionItem>
As a result, I’d like the output file to look like :
<CollectionItem>
<Item>
<var1>5</var1>
<var2>20</var2>
</Item>
<Item>
<var1>10</var>
<var2>5</var2>
</Item>
</CollectionItem>
Furthermore, I’d like to be generic, if I add a field in the node Item, I don’t want to code it but rather read it in the default XML file.
Thanks for your help !
read the XML files using the XElemnt class.
you get the child elements using the method Elements().
each element has a property “name”.
if the non-default element doesn’t have a field that the default element has – add it with the Add function.
at the end don’t forget to call the function “save”.