There are three Nuget packages available:
Simply call one of the static AreEqual overloaded methods. AreEqual can compare between two XElement objects that represent the root of the XML document or two strings. In the later case the strings are parsed into XDocument objects:
const string xmlA = @"<?xml version=""1.0"" encoding=""UTF-8""?> <a:root xmlns:a=""http://test.com/testing""/>"; const string xmlB = @"<?xml version=""1.0"" encoding=""UTF-8""?> <root xmlns=""http://test.com/testing""> </root>"; var result = XmlSpecificationEquality.AreEqual(xmlA, xmlB);
if (!result.Success) { Console.Writeline(result.ErrorMessage); Console.Writeline("Compare failed at " + result.FailObject.GetXPath()); }
XPath discovery is provided by the XpathExtension class which defines the XObject extension method GetXPath() which returns a simple XPath to the XObject in question. For a usage example look at the second to last line in the example above.
The only types of XObject currently supported are:
Simple Assertion:
Assert.That(xmlA, XmlIs.SpecificationEquals(xmlB))
Complex Assertion:
Assert.That(xmlA, Is.Not.XmlEquals(xmlB)); Assert.That(xmlList, Is.All.XmlEquals(xmlB))