简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM