Quantcast
Channel: Programmatic XML Diff / Merge in C# - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Programmatic XML Diff / Merge in C#

$
0
0

At this moment, I am managing a piece of software that has multiple XML configuration files. When a new version of software is released, sometimes the base config files change, we currently have the software call KDiff on startup. If it detects a change, it prompts the user to choose the changes.

The problem with this approach is that KDiff is a line comparing program and not aware of the ways of XML (like Nodes, etc.)

Ideally, I would like to programmatically work with a library in C# (since we're a MS shop) that can Diff two XML files: a Source XML and a Current Working XML.

And then Merge the two together using a few simple rules:

  1. If the Current Working XML has a node that the Source XML does not, remove it.
  2. If the Source XML has a node that the Current Working XML does not, add it.
  3. If both have the same node and the values differ, favor the Source XML's value, unless it the Source XML's value is set to "UseExistingValue".

For example, here's the "Source" XML:

<Configuration><Items><Item Id="1" Position="true"><Location X="UseExistingValue" Y="UseExistingValue" Z="UseExistingValue" /><Something/><SomethingElse/></Item></Items></Configuration>

And here's the "Current Working" XML:

<Configuration><Items><Item Id="1" Position="false"><Location X="123" Y="234" Z="345" /><Another/><Something/></Item></Items></Configuration>

And the merged version would look like:

<Configuration><Items><Item Id="1" Position="true"><Location X="123" Y="234" Z="345" /><Something/><SomethingElse/></Item></Items></Configuration>

I've looked at the MS XML Diff and Patch Tool and it definitely merges the files together, but doesn't allow for the programmatic rules that I want to define.

XMLUnit for Java devs seems promising, but the .NET version of it seems underdeveloped, which is unfortunate.

Anyone have any suggestions for either scriptable XML Diff/Merge tools and/or .NET libraries (paid or free)?

Thanks.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images