Search code examples
c#xmlunit

How to print ALL the discrepencies between two XML documents


I just discovered this nice tool XmlUnit that allows me to evaluate 2 different XML documents and display the eventual discrepencies.

string control = "<a><b attr=\"abc\"></b></a>";
string test = "<a><b attr=\"xyz\"></b></a>";

var myDiff = DiffBuilder.Compare(Input.FromString(control))
              .WithTest(Input.FromString(test))
              .Build();

Assert.IsFalse(myDiff.HasDifferences(), myDiff.ToString());

However, I have found that the myDiff.ToString() only displays the first difference encountered. Is there a way to display them all ?


Solution

  • I just found the solution

    Assert.IsFalse(myDiff.HasDifferences(), string.Join(Environment.NewLine, myDiff.Differences));