0

If I have an xml file that does not necessarily have a strong schema and has many nodes, some may even be nested nodes - how can I compare with another xml string and update the destination with any updated values (and nodes perhaps)?

so if my input source had something like (and this can vary, it can be anything):

<updates>
<id>3</id>
<customer>
   <source>CW</source>
   <number>433</number>
   <name>Jones</name>  
</customer>
</updates>

Now, if I read a destination xml file/string from some source, it may contain the above structure or a different structure. I want to be able to update it by going through the nodes from the source above. So my destination XML could have something like:

<updates>
<id>3</id>
<customer>
   <engine>Some engine</engine>
   <number>43213</number>
   <name>Taz</name> 
   <duration>4</duration>
</customer>
</updates>

The destination above would have the name and number updated because these 2 exist in the source file.

any ideas how to do this? Remember: it is not possible to know ahead of time what the xml nodes will be but do need to match and update if found.

thank you.

Ahmed ilyas
  • 5,722
  • 8
  • 44
  • 72
  • As this isn't generally a code writing service, what have you got so far? Questions like [this one](http://stackoverflow.com/questions/982597/what-is-the-fastest-way-to-combine-two-xml-files-into-one) should get you started if you haven't already. – Charles Mager Jun 10 '16 at 18:09
  • Thanks. Currently I don't have anything but the link provided was good however it does not fit my needs since I am NOT doing combining of the xml but rather updating the nodes that exist from source along with the destination if the destination has those nodes too. – Ahmed ilyas Jun 10 '16 at 18:40
  • It's not that dissimilar, you just have a different method of combining them (i.e. find element in target, update its value if it exists). – Charles Mager Jun 10 '16 at 18:42
  • So how would you do that exactly? I mean you need to read the source and iterate through it, right? so when you are iterating through, how do you find the current node in the destination? – Ahmed ilyas Jun 10 '16 at 18:45
  • 1
    Unless you have a more specific question, this looks to be a duplicate of [Programmatic XML Diff / Merge in C#](https://stackoverflow.com/questions/14341490) or [How would you compare two XML Documents?](https://stackoverflow.com/questions/167946). Both point to Microsoft's [XML Diff and Patch Tool](https://msdn.microsoft.com/en-us/library/aa302294.aspx). – dbc Jun 10 '16 at 22:00

0 Answers0