Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it better to use XNodeEqualityComparer or XElement.DeepEquals to compare xml objects?

Tags:

c#

xml

I need to compare two xml documents.

Assume that each of the following XElement's load from a Stream:

XElement actualElement = XElement.Load(actual);
XElement expectedElement = XElement.Load(expected);

Using that, which of the following two is better:

XNodeEqualityComparer comparer = new XNodeEqualityComparer();
comparer.Equals(actualElement, expectedElement);

or

XElement.DeepEquals(actualElement, expectedElement);

I know that the second option is shorter, but I am more interested in whether or not you get any speed improvements or better/deeper comparison when using one or the other. The comparison itself needs to compare the elements, attributes, and all values between the two xml documents.

like image 463
schellack Avatar asked Feb 04 '11 22:02

schellack


1 Answers

The XNodeEqualityComparer.Equals method simply calls the XNode.DeepEquals method. So there is no difference between the two calls.

like image 83
dtb Avatar answered Sep 20 '22 15:09

dtb