Skip to content

pure c# library to find the changes between two xml files

Notifications You must be signed in to change notification settings

YonatanRubin/XmlDiff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XML DIFF

Quick Start

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"});

Use Case

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:

  • 2 was removed
  • 3 was removed
  • 4 was inserted

in reality it will detect 2 changes:

  • 2/3 was removed
  • 2/3 was changed to 4
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:

  • name and kind removed
  • company type and year changed
  • the object type was changed from dog to car

About

pure c# library to find the changes between two xml files

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages