nuget install XmlDiff
To compare two documents:
var a=XElement.Load("a.xml");
var b=XElement.Load("b.xml");
FlatDiffComparer comparer=new FlatDiffComparer();
IEnumerable<FlatNodeDiff> diffs=comparer.Compare(a,b);
To find all tags sub
that were deleted
diffs.Where(diff => diff.Name == "sub" && diff.GetChangeType() == ChangeType.Removed);
To filter all diffs under tag ignore
you can use the ComplexFlatDiffComparer
ComplexFlatDiffComparer comparer=new ComplexFlatDiffComparer(new[]{"ignore"});
This library allows you to compute the absolute difference between two xml files. It is therefore best used when computing the diff between similar xml objects. See example [2]
It will try to minimize the number of changes.
Meaning that some changes might logically come from multiple changes. See example [1].
This is deliberate to prevent sticky situations with overly complex changes based on the order of the items.
Keep in mind that for complex items in list you should use the IdPaths
feature and read more about it's known problems here
Example No. | Document 1 | Document 2 | Diffs |
---|---|---|---|
1 |
<document>
<array>
<item>1</item>
<item>2</item>
<item>3</item>
</array>
</document> |
<document>
<array>
<item>4</item>
<item>1</item>
</array>
</document> |
even though logically it may look like there were three changes:
in reality it will detect 2 changes:
|
2 |
<dog>
<name>Buffy</name>
<kind>Golden Retriever</kind>
</dog> |
<car>
<company>hundai</company>
<type>i30</type>
<year>2013</year>
</car> |
will have multiple diffs:
|